Skip to content

Commit

Permalink
Move the lock method to list.rs and rename it to try_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull committed Mar 31, 2023
1 parent 1a4df18 commit 2d171ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct Inner {
/// The number of notified entries, or `usize::MAX` if all of them have been notified.
///
/// If there are no entries, this value is set to `usize::MAX`.
pub(crate) notified: AtomicUsize,
notified: AtomicUsize,

/// Inner queue of event listeners.
list: list::List,
Expand All @@ -179,14 +179,6 @@ impl Inner {
list: list::List::new(),
}
}

/// Locks the list.
pub(crate) fn lock(&self) -> Option<list::ListGuard<'_>> {
self.list.inner.try_lock().map(|guard| list::ListGuard {
inner: self,
guard: Some(guard),
})
}
}

/// A synchronization primitive for notifying async tasks and threads.
Expand Down
8 changes: 8 additions & 0 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ use core::ops;
use slab::Slab;

impl crate::Inner {
/// Locks the list.
fn lock(&self) -> Option<ListGuard<'_>> {
self.list.inner.try_lock().map(|guard| ListGuard {
inner: self,
guard: Some(guard),
})
}

/// Add a new listener to the list.
///
/// Does nothing if the list is already registered.
Expand Down

0 comments on commit 2d171ae

Please sign in to comment.