Skip to content

Commit

Permalink
fix for Pauan#82
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronbraid committed Mar 5, 2024
1 parent 9c9c4c8 commit ec265d4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/signal/broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::pin::Pin;
use std::marker::Unpin;
use std::fmt::Debug;
use std::sync::{Arc, Mutex, RwLock, Weak};
use std::sync::atomic::{AtomicBool, Ordering};
// use std::sync::atomic::{AtomicBool, Ordering};
use std::task::{Poll, Waker, Context};
use futures_util::task::{self, ArcWake};

Expand All @@ -16,22 +16,22 @@ use crate::signal::ChangedWaker;
/// then wake up all of the child ChangedWaker.
#[derive(Debug)]
struct BroadcasterNotifier {
is_changed: AtomicBool,
// is_changed: AtomicBool,
wakers: Mutex<Vec<Weak<ChangedWaker>>>,
}

impl BroadcasterNotifier {
fn new() -> Self {
Self {
is_changed: AtomicBool::new(true),
// is_changed: AtomicBool::new(true),
wakers: Mutex::new(vec![]),
}
}

fn notify(&self) {
let mut lock = self.wakers.lock().unwrap();

self.is_changed.store(true, Ordering::SeqCst);
// self.is_changed.store(true, Ordering::SeqCst);

// Take this opportunity to GC dead wakers
lock.retain(|waker| {
Expand All @@ -45,9 +45,9 @@ impl BroadcasterNotifier {
});
}

fn is_changed(&self) -> bool {
self.is_changed.swap(false, Ordering::SeqCst)
}
// fn is_changed(&self) -> bool {
// self.is_changed.swap(false, Ordering::SeqCst)
// }
}

impl ArcWake for BroadcasterNotifier {
Expand Down Expand Up @@ -129,18 +129,18 @@ impl<A> BroadcasterSharedState<A> where A: Signal {
}

fn poll<B, F>(&self, f: F) -> B where F: FnOnce(&BroadcasterInnerState<A>) -> B {
if self.notifier.is_changed() {
// if self.notifier.is_changed() {
let mut lock = self.inner.write().unwrap();

lock.poll_signal();

f(&lock)

} else {
let lock = self.inner.read().unwrap();
// } else {
// let lock = self.inner.read().unwrap();

f(&lock)
}
// f(&lock)
// }
}
}

Expand Down

0 comments on commit ec265d4

Please sign in to comment.