From 6f092bcad94d466e4d7aedc42dad4f7c606161d4 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 2 Dec 2023 21:37:23 +0900 Subject: [PATCH] Remove dependency on scopeguard --- crossbeam-epoch/Cargo.toml | 1 - crossbeam-epoch/src/guard.rs | 21 ++++++++++++--------- crossbeam-skiplist/Cargo.toml | 4 ---- crossbeam-skiplist/src/base.rs | 10 +++++++--- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/crossbeam-epoch/Cargo.toml b/crossbeam-epoch/Cargo.toml index 630c5e8fa..d959a447c 100644 --- a/crossbeam-epoch/Cargo.toml +++ b/crossbeam-epoch/Cargo.toml @@ -39,7 +39,6 @@ autocfg = "1" [dependencies] cfg-if = "1" memoffset = "0.9" -scopeguard = { version = "1.1", default-features = false } # Enable the use of loom for concurrency testing. # diff --git a/crossbeam-epoch/src/guard.rs b/crossbeam-epoch/src/guard.rs index da1c5c01b..5fe33807c 100644 --- a/crossbeam-epoch/src/guard.rs +++ b/crossbeam-epoch/src/guard.rs @@ -1,8 +1,6 @@ use core::fmt; use core::mem; -use scopeguard::defer; - use crate::atomic::Shared; use crate::collector::Collector; use crate::deferred::Deferred; @@ -366,6 +364,17 @@ impl Guard { where F: FnOnce() -> R, { + // Ensure the Guard is re-pinned even if the function panics + struct ScopeGuard(*const Local); + impl Drop for ScopeGuard { + fn drop(&mut self) { + if let Some(local) = unsafe { self.0.as_ref() } { + mem::forget(local.pin()); + local.release_handle(); + } + } + } + if let Some(local) = unsafe { self.local.as_ref() } { // We need to acquire a handle here to ensure the Local doesn't // disappear from under us. @@ -373,13 +382,7 @@ impl Guard { local.unpin(); } - // Ensure the Guard is re-pinned even if the function panics - defer! { - if let Some(local) = unsafe { self.local.as_ref() } { - mem::forget(local.pin()); - local.release_handle(); - } - } + let _guard = ScopeGuard(self.local); f() } diff --git a/crossbeam-skiplist/Cargo.toml b/crossbeam-skiplist/Cargo.toml index 1828961d7..cbf524087 100644 --- a/crossbeam-skiplist/Cargo.toml +++ b/crossbeam-skiplist/Cargo.toml @@ -41,10 +41,6 @@ version = "0.8.5" path = "../crossbeam-utils" default-features = false -[dependencies.scopeguard] -version = "1.1.0" -default-features = false - [dev-dependencies] rand = "0.8" diff --git a/crossbeam-skiplist/src/base.rs b/crossbeam-skiplist/src/base.rs index cd8488601..f8e26c496 100644 --- a/crossbeam-skiplist/src/base.rs +++ b/crossbeam-skiplist/src/base.rs @@ -937,9 +937,13 @@ where // We failed. Let's search for the key and try again. { // Create a guard that destroys the new node in case search panics. - let sg = scopeguard::guard((), |_| { - Node::finalize(node.as_raw()); - }); + struct ScopeGuard(*const Node); + impl Drop for ScopeGuard { + fn drop(&mut self) { + unsafe { Node::finalize(self.0) } + } + } + let sg = ScopeGuard(node.as_raw()); search = self.search_position(&n.key, guard); mem::forget(sg); }