From 244c55f9ce828f0582af8ffa59943e9716a70fd7 Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Mon, 23 Dec 2024 11:12:23 -0800 Subject: [PATCH] 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. --- src/fd_monitor.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/fd_monitor.rs b/src/fd_monitor.rs index abf91168a..2176271b9 100644 --- a/src/fd_monitor.rs +++ b/src/fd_monitor.rs @@ -4,7 +4,7 @@ use std::os::unix::prelude::*; #[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, /// 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, + change_signaller: Arc, /// The data shared between the background thread and the `FdMonitor` instance. data: Arc>, } @@ -325,7 +325,7 @@ impl FdMonitor { 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 @@ impl BackgroundFdMonitor { 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 @@ impl BackgroundFdMonitor { 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`