Skip to content

Commit e88c379

Browse files
committed
avoid accessing allocation counters when epochs are disabled
1 parent 5111b4e commit e88c379

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/raw.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,23 @@ impl Collector {
4242

4343
// Create a new node.
4444
pub fn node(&self) -> Node {
45-
// safety: node counts are only accessed by the current thread
46-
let count = unsafe { &mut *self.node_count.load(Thread::current()).get() };
47-
*count += 1;
48-
4945
// record the current epoch value
5046
//
5147
// note that it's fine if we see older epoch values here, which just means more
5248
// threads will be counted as active than might actually be
5349
let birth_epoch = match self.epoch_frequency {
54-
// advance the global epoch
55-
Some(ref freq) if *count % freq.get() == 0 => {
56-
self.epoch.fetch_add(1, Ordering::Relaxed) + 1
50+
Some(ref epoch_frequency) => {
51+
// safety: node counts are only accessed by the current thread
52+
let count = unsafe { &mut *self.node_count.load(Thread::current()).get() };
53+
*count += 1;
54+
55+
// advance the global epoch
56+
if *count % epoch_frequency.get() == 0 {
57+
self.epoch.fetch_add(1, Ordering::Relaxed) + 1
58+
} else {
59+
self.epoch.load(Ordering::Relaxed)
60+
}
5761
}
58-
Some(_) => self.epoch.load(Ordering::Relaxed),
5962
// we aren't tracking epochs
6063
None => 0,
6164
};

0 commit comments

Comments
 (0)