Skip to content

Commit

Permalink
try use not static atomicusize in loom test
Browse files Browse the repository at this point in the history
  • Loading branch information
wathenjiang committed Sep 25, 2023
1 parent a30df11 commit 51c540b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ rt = []
rt-multi-thread = [
"num_cpus",
"rt",
"once_cell"
]
signal = [
"libc",
Expand All @@ -98,6 +99,7 @@ bytes = { version = "1.0.0", optional = true }
mio = { version = "0.8.6", optional = true, default-features = false }
num_cpus = { version = "1.8.0", optional = true }
parking_lot = { version = "0.12.0", optional = true }
once_cell = {version = "1.18.0", optional = true}

[target.'cfg(not(target_family = "wasm"))'.dependencies]
socket2 = { version = "0.5.3", optional = true, features = [ "all" ] }
Expand Down
11 changes: 11 additions & 0 deletions tokio/src/runtime/task/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl fmt::Display for Id {
}

impl Id {
#[cfg(not(loom))]
pub(crate) fn next() -> Self {
use crate::loom::sync::atomic::{Ordering::Relaxed, StaticAtomicU64};

Expand All @@ -81,6 +82,16 @@ impl Id {
Self(NEXT_ID.fetch_add(1, Relaxed))
}

#[cfg(loom)]
pub(crate) fn next() -> Self {
use crate::loom::sync::atomic::{AtomicU64, Ordering::Relaxed};
use once_cell::sync::Lazy;

static NEXT_ID: Lazy<AtomicU64> = Lazy::new(|| AtomicU64::new(1));

Self(NEXT_ID.fetch_add(1, Relaxed))
}

pub(crate) fn as_u64(&self) -> u64 {
self.0
}
Expand Down

0 comments on commit 51c540b

Please sign in to comment.