Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable early-out notify optimizations #139

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ use sync::Arc;
#[cfg(not(loom))]
use sync::WithMut;

use notify::{Internal, NotificationPrivate};
use notify::NotificationPrivate;
pub use notify::{IntoNotification, Notification};

/// Inner state of [`Event`].
Expand Down Expand Up @@ -437,21 +437,8 @@ impl<T> Event<T> {
// Make sure the notification comes after whatever triggered it.
notify.fence(notify::Internal::new());

if let Some(inner) = self.try_inner() {
let limit = if notify.is_additional(Internal::new()) {
usize::MAX
} else {
notify.count(Internal::new())
};

// Notify if there is at least one unnotified listener and the number of notified
// listeners is less than `limit`.
if inner.needs_notification(limit) {
return inner.notify(notify);
}
}

0
let inner = unsafe { &*self.inner() };
taiki-e marked this conversation as resolved.
Show resolved Hide resolved
inner.notify(notify)
}

/// Return a reference to the inner state if it has been initialized.
Expand Down
5 changes: 0 additions & 5 deletions src/no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ impl<T> crate::Inner<T> {
drop(self.try_lock());
}

pub(crate) fn needs_notification(&self, _limit: usize) -> bool {
// TODO: Figure out a stable way to do this optimization.
true
}

/// Add a new listener to the list.
///
/// Does nothing if the list is already registered.
Expand Down
5 changes: 0 additions & 5 deletions src/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ impl<T> crate::Inner<T> {
}
}

/// Whether or not this number of listeners would lead to a notification.
pub(crate) fn needs_notification(&self, limit: usize) -> bool {
self.notified.load(Ordering::Acquire) < limit
}

/// Add a new listener to the list.
pub(crate) fn insert(&self, mut listener: Pin<&mut Option<Listener<T>>>) {
let mut inner = self.lock();
Expand Down
Loading