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

[maitake-sync]: Provide "is_closed" methods for WaitCell/WaitMap/WaitQueue #480

Merged
merged 3 commits into from
Jul 18, 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
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 {
hawkw marked this conversation as resolved.
Show resolved Hide resolved
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 {
hawkw marked this conversation as resolved.
Show resolved Hide resolved
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).
hawkw marked this conversation as resolved.
Show resolved Hide resolved
#[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
Loading