Skip to content

Commit f9f0ad6

Browse files
committed
use integer ID for collector uniqueness
1 parent 90b9e7b commit f9f0ad6

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/collector.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::tls::Thread;
22
use crate::{raw, LocalGuard, OwnedGuard};
33

44
use std::cell::UnsafeCell;
5+
use std::fmt;
56
use std::num::NonZeroU64;
6-
use std::sync::atomic::Ordering;
7-
use std::{fmt, ptr};
7+
use std::sync::atomic::{AtomicUsize, Ordering};
88

99
/// Fast, efficient, and robust memory reclamation.
1010
///
@@ -13,8 +13,8 @@ use std::{fmt, ptr};
1313
/// the [`enter`](Collector::enter) or [`enter_owned`](Collector::enter_owned)
1414
/// methods.
1515
pub struct Collector {
16+
id: usize,
1617
pub(crate) raw: raw::Collector,
17-
unique: *mut u8,
1818
}
1919

2020
unsafe impl Send for Collector {}
@@ -26,13 +26,15 @@ impl Collector {
2626

2727
/// Creates a new collector.
2828
pub fn new() -> Self {
29+
static ID: AtomicUsize = AtomicUsize::new(0);
30+
2931
let cpus = std::thread::available_parallelism()
3032
.map(Into::into)
3133
.unwrap_or(1);
3234

3335
Self {
3436
raw: raw::Collector::new(cpus, Self::DEFAULT_EPOCH_TICK, Self::DEFAULT_RETIRE_TICK),
35-
unique: Box::into_raw(Box::new(0)),
37+
id: ID.fetch_add(1, Ordering::Relaxed),
3638
}
3739
}
3840

@@ -284,14 +286,8 @@ impl Collector {
284286
unsafe { self.raw.reclaim_all() };
285287
}
286288

287-
pub(crate) fn ptr_eq(this: &Collector, other: &Collector) -> bool {
288-
ptr::eq(this.unique, other.unique)
289-
}
290-
}
291-
292-
impl Drop for Collector {
293-
fn drop(&mut self) {
294-
let _ = unsafe { Box::from_raw(self.unique) };
289+
pub(crate) fn id_eq(this: &Collector, other: &Collector) -> bool {
290+
this.id == other.id
295291
}
296292
}
297293

src/guard.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl Guard for LocalGuard<'_> {
167167

168168
/// Returns `true` if this guard belongs to the given collector.
169169
fn belongs_to(&self, collector: &Collector) -> bool {
170-
Collector::ptr_eq(self.collector, collector)
170+
Collector::id_eq(self.collector, collector)
171171
}
172172
}
173173

@@ -274,7 +274,7 @@ impl Guard for OwnedGuard<'_> {
274274

275275
/// Returns `true` if this guard belongs to the given collector.
276276
fn belongs_to(&self, collector: &Collector) -> bool {
277-
Collector::ptr_eq(self.collector, collector)
277+
Collector::id_eq(self.collector, collector)
278278
}
279279
}
280280

0 commit comments

Comments
 (0)