Skip to content

Commit

Permalink
Seal the Notification and IntoNotification traits
Browse files Browse the repository at this point in the history
This PR seals these two traits to prevent breaking changes from causing
semver breaks. It also adds documentation to both traits.
  • Loading branch information
notgull committed Apr 4, 2023
1 parent 723c328 commit 15b4ea2
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 72 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ use std::time::{Duration, Instant};
use sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
use sync::{Arc, WithMut};

pub use notify::{Additional, IntoNotification, Notification, Notify, Tag, TagWith};
use notify::{Internal, NotificationPrivate};
pub use notify::{IntoNotification, Notification};

/// Useful traits for notifications.
pub mod prelude {
Expand Down Expand Up @@ -343,13 +344,13 @@ impl<T> Event<T> {
let notify = notify.into_notification();

// Make sure the notification comes after whatever triggered it.
notify.fence();
notify.fence(notify::Internal::new());

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

// Notify if there is at least one unnotified listener and the number of notified
Expand Down
16 changes: 8 additions & 8 deletions src/no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod queue;
use node::{Node, TaskWaiting};
use queue::Queue;

use crate::notify::{GenericNotify, Notification};
use crate::notify::{GenericNotify, Internal, Notification};
use crate::sync::atomic::{AtomicBool, Ordering};
use crate::sync::cell::{Cell, UnsafeCell};
use crate::sync::Arc;
Expand Down Expand Up @@ -121,15 +121,15 @@ impl<T> crate::Inner<T> {
None => {
// Push it to the queue.
let node = Node::Notify(GenericNotify::new(
notify.count(),
notify.is_additional(),
notify.count(Internal::new()),
notify.is_additional(Internal::new()),
{
// Collect every tag we need.
let mut tags = {
let count = notify.count();
let count = notify.count(Internal::new());
let mut tags = Vec::with_capacity(count);
for _ in 0..count {
tags.push(notify.next_tag());
tags.push(notify.next_tag(Internal::new()));
}

// Convert into an iterator.
Expand Down Expand Up @@ -571,8 +571,8 @@ impl<T> ListenerSlab<T> {
/// Notifies a number of listeners.
#[cold]
pub(crate) fn notify(&mut self, mut notify: impl Notification<Tag = T>) {
let mut n = notify.count();
let is_additional = notify.is_additional();
let mut n = notify.count(Internal::new());
let is_additional = notify.is_additional(Internal::new());
if !is_additional {
// Make sure we're not notifying more than we have.
if n <= self.notified {
Expand All @@ -594,7 +594,7 @@ impl<T> ListenerSlab<T> {
self.start = entry.next().get();

// Set the state to `Notified` and notify.
let tag = notify.next_tag();
let tag = notify.next_tag(Internal::new());
if let State::Task(task) = entry.state().replace(State::Notified {
tag,
additional: is_additional,
Expand Down
4 changes: 2 additions & 2 deletions src/no_std/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<T> Drop for Queue<T> {

#[cfg(test)]
mod tests {
use crate::notify::{GenericNotify, Notification};
use crate::notify::{GenericNotify, Internal, NotificationPrivate};

use super::*;

Expand All @@ -139,7 +139,7 @@ mod tests {

fn node_to_num(node: Node<()>) -> usize {
match node {
Node::Notify(notify) => notify.count(),
Node::Notify(notify) => notify.count(Internal::new()),
_ => panic!("unexpected node"),
}
}
Expand Down
Loading

0 comments on commit 15b4ea2

Please sign in to comment.