-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tokio: use const Mutex::new
for globals
#5061
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -507,21 +507,35 @@ impl Id { | |
} | ||
|
||
cfg_not_has_atomic_u64! { | ||
pub(crate) fn next() -> Self { | ||
use crate::util::once_cell::OnceCell; | ||
use crate::loom::sync::Mutex; | ||
|
||
fn init_next_id() -> Mutex<u64> { | ||
Mutex::new(1) | ||
cfg_has_const_mutex_new! { | ||
pub(crate) fn next() -> Self { | ||
use crate::loom::sync::Mutex; | ||
static NEXT_ID: Mutex<u64> = Mutex::const_new(1); | ||
|
||
let mut lock = NEXT_ID.lock(); | ||
let id = *lock; | ||
*lock += 1; | ||
Self(id) | ||
} | ||
} | ||
|
||
static NEXT_ID: OnceCell<Mutex<u64>> = OnceCell::new(); | ||
cfg_not_has_const_mutex_new! { | ||
pub(crate) fn next() -> Self { | ||
use crate::util::once_cell::OnceCell; | ||
use crate::loom::sync::Mutex; | ||
|
||
let next_id = NEXT_ID.get(init_next_id); | ||
let mut lock = next_id.lock(); | ||
let id = *lock; | ||
*lock += 1; | ||
Self(id) | ||
fn init_next_id() -> Mutex<u64> { | ||
Mutex::new(1) | ||
} | ||
|
||
static NEXT_ID: OnceCell<Mutex<u64>> = OnceCell::new(); | ||
|
||
let next_id = NEXT_ID.get(init_next_id); | ||
let mut lock = next_id.lock(); | ||
let id = *lock; | ||
*lock += 1; | ||
Self(id) | ||
} | ||
Comment on lines
+510
to
+538
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, it might be nice if the logic that actually advances the next id was not duplicated across cfgs, but i'm not sure if there's a nice way to do that without changes to the macro to take a block instead of an item, which would make it different from the rest of the |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, take it or leave it: would it make sense to simplify this by just having the build script not set the
tokio_no_const_mutex_new
cfg when theloom
andtest
cfgs are set? or is this simpler?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is the simplest option.