Skip to content

Commit

Permalink
fix unsafe/incorrect crossbeam-epoch usage in Block<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz committed Dec 22, 2023
1 parent 6e3f710 commit a818f50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions metrics-util/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - ReleaseDate

### Fixed

- Fixed the `Debug` implementation for `bucket::Block<T>` which represented both an unsafe and
logically incorrect usage of `crossbeam-epoch.`

## [0.15.1] - 2023-07-02

### Added
Expand Down
5 changes: 3 additions & 2 deletions metrics-util/src/bucket.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crossbeam_epoch::{pin as epoch_pin, unprotected, Atomic, Guard, Owned, Shared};
use crossbeam_epoch::{pin as epoch_pin, Atomic, Guard, Owned, Shared};
use crossbeam_utils::Backoff;
use std::{
cell::UnsafeCell,
Expand Down Expand Up @@ -153,7 +153,8 @@ impl<T> Drop for Block<T> {

impl<T> std::fmt::Debug for Block<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let has_next = unsafe { !self.next.load(Ordering::Acquire, unprotected()).is_null() };
let guard = &epoch_pin();
let has_next = !self.next.load(Ordering::Acquire, guard).is_null();
f.debug_struct("Block")
.field("type", &std::any::type_name::<T>())
.field("block_size", &BLOCK_SIZE)
Expand Down

0 comments on commit a818f50

Please sign in to comment.