Skip to content

Commit

Permalink
Remove dependency on scopeguard
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 13, 2023
1 parent ac0b414 commit ac3d0f6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
1 change: 0 additions & 1 deletion crossbeam-epoch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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.
#
Expand Down
21 changes: 12 additions & 9 deletions crossbeam-epoch/src/guard.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -366,20 +364,25 @@ 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.
local.acquire_handle();
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()
}
Expand Down
4 changes: 0 additions & 4 deletions crossbeam-skiplist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,5 @@ version = "0.8.5"
path = "../crossbeam-utils"
default-features = false

[dependencies.scopeguard]
version = "1.1.0"
default-features = false

[dev-dependencies]
rand = "0.8"
10 changes: 7 additions & 3 deletions crossbeam-skiplist/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K, V>(*const Node<K, V>);
impl<K, V> Drop for ScopeGuard<K, V> {
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);
}
Expand Down

0 comments on commit ac3d0f6

Please sign in to comment.