Skip to content

Commit

Permalink
feat(maitake-sync): add is_closed methods to WaitCell/WaitMap/`…
Browse files Browse the repository at this point in the history
…WaitQueue` (#480)

This commit adds methods for synchronously testing whether a `WaitCell`,
`WaitQueue`, or `WaitMap` has been closed by a call to the corresponding
`close` method.
  • Loading branch information
jamesmunns authored Jul 18, 2024
1 parent 6dc5a84 commit c67c62f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 3 additions & 5 deletions maitake-sync/src/wait_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,11 @@ impl WaitCell {
}
}

// TODO(eliza): is this an API we want to have?
/*
/// Returns `true` if this `WaitCell` is [closed](Self::close).
pub(crate) fn is_closed(&self) -> bool {
self.current_state() == State::CLOSED
#[must_use]
pub fn is_closed(&self) -> bool {
self.current_state() == State::CLOSED
}
*/

/// Takes this `WaitCell`'s waker.
// TODO(eliza): could probably be made a public API...
Expand Down
6 changes: 6 additions & 0 deletions maitake-sync/src/wait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ impl<K: PartialEq, V> WaitMap<K, V> {
}
}

/// Returns `true` if this `WaitMap` is [closed](Self::close).
#[must_use]
pub fn is_closed(&self) -> bool {
self.load() == State::Closed
}

/// Close the queue, indicating that it may no longer be used.
///
/// Once a queue is closed, all [`wait`] calls (current or future) will
Expand Down
6 changes: 6 additions & 0 deletions maitake-sync/src/wait_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,12 @@ impl WaitQueue {
}
}

/// Returns `true` if this `WaitQueue` is [closed](Self::close).
#[must_use]
pub fn is_closed(&self) -> bool {
self.load().get(QueueState::STATE) == State::Closed
}

/// Returns a [`Waiter`] entry in this queue.
///
/// This is factored out into a separate function because it's used by both
Expand Down

0 comments on commit c67c62f

Please sign in to comment.