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

feat: add forget method to semaphore guards #73

Merged
merged 7 commits into from
Dec 11, 2023
Merged
Changes from 2 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
14 changes: 14 additions & 0 deletions src/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ impl EventListenerFuture for AcquireArcInner {
#[derive(Debug)]
pub struct SemaphoreGuard<'a>(&'a Semaphore);

impl SemaphoreGuard<'_> {
/// Drops the guard _without_ releasing the acquired permit.
pub fn forget(self) {
let _ = core::mem::ManuallyDrop::new(self);
Jules-Bertholet marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl Drop for SemaphoreGuard<'_> {
fn drop(&mut self) {
self.0.count.fetch_add(1, Ordering::AcqRel);
Expand All @@ -349,6 +356,13 @@ impl Drop for SemaphoreGuard<'_> {
#[derive(Debug)]
pub struct SemaphoreGuardArc(Arc<Semaphore>);

impl SemaphoreGuardArc {
/// Drops the guard _without_ releasing the acquired permit.
pub fn forget(self) {
let _ = core::mem::ManuallyDrop::new(self);
}
}

impl Drop for SemaphoreGuardArc {
fn drop(&mut self) {
self.0.count.fetch_add(1, Ordering::AcqRel);
Expand Down