mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-06 00:41:15 -03:00
FdMonitor: change_signaller to be held strongly not weakly
There's no reason to use Weak here, especially since we just unwrap it. There's no reference cycles, so just share the data via Arc.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#[cfg(target_has_atomic = "64")]
|
||||
use std::sync::atomic::AtomicU64;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::{Arc, Mutex, Weak};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::common::exit_without_destructors;
|
||||
@@ -291,7 +291,7 @@ struct BackgroundFdMonitor {
|
||||
items: Vec<FdMonitorItem>,
|
||||
/// Our self-signaller. When this is written to, it means there are new items pending, new items
|
||||
/// in the poke list, or terminate has been set.
|
||||
change_signaller: Weak<FdEventSignaller>,
|
||||
change_signaller: Arc<FdEventSignaller>,
|
||||
/// The data shared between the background thread and the `FdMonitor` instance.
|
||||
data: Arc<Mutex<SharedData>>,
|
||||
}
|
||||
@@ -325,7 +325,7 @@ pub fn add(&self, mut item: FdMonitorItem) -> FdMonitorItemId {
|
||||
FLOG!(fd_monitor, "Thread starting");
|
||||
let background_monitor = BackgroundFdMonitor {
|
||||
data: Arc::clone(&self.data),
|
||||
change_signaller: Arc::downgrade(&self.change_signaller),
|
||||
change_signaller: Arc::clone(&self.change_signaller),
|
||||
items: Vec::new(),
|
||||
};
|
||||
crate::threads::spawn(move || {
|
||||
@@ -389,7 +389,7 @@ fn run(mut self) {
|
||||
fds.clear();
|
||||
|
||||
// Our change_signaller is special-cased
|
||||
let change_signal_fd = self.change_signaller.upgrade().unwrap().read_fd();
|
||||
let change_signal_fd = self.change_signaller.read_fd();
|
||||
fds.add(change_signal_fd);
|
||||
|
||||
for item in &mut self.items {
|
||||
@@ -437,7 +437,7 @@ fn run(mut self) {
|
||||
let change_signalled = fds.test(change_signal_fd);
|
||||
if change_signalled || is_wait_lap {
|
||||
// Clear the change signaller before processing incoming changes
|
||||
self.change_signaller.upgrade().unwrap().try_consume();
|
||||
self.change_signaller.try_consume();
|
||||
let mut data = self.data.lock().expect("Mutex poisoned!");
|
||||
|
||||
// Move from `pending` to the end of `items`
|
||||
|
||||
Reference in New Issue
Block a user