mirror of
https://github.com/tokio-rs/tracing.git
synced 2026-03-19 06:12:30 +00:00
core: additional deprecation fixes (#1606)
This should *actually* fix the build on no-std. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
This commit is contained in:
@@ -76,24 +76,32 @@ impl<T> Once<T> {
|
||||
let mut status = self.state.load(Ordering::SeqCst);
|
||||
|
||||
if status == INCOMPLETE {
|
||||
status = self
|
||||
.state
|
||||
.compare_and_swap(INCOMPLETE, RUNNING, Ordering::SeqCst);
|
||||
if status == INCOMPLETE {
|
||||
// We init
|
||||
// We use a guard (Finish) to catch panics caused by builder
|
||||
let mut finish = Finish {
|
||||
state: &self.state,
|
||||
panicked: true,
|
||||
};
|
||||
unsafe { *self.data.get() = Some(builder()) };
|
||||
finish.panicked = false;
|
||||
status = match self.state.compare_exchange(
|
||||
INCOMPLETE,
|
||||
RUNNING,
|
||||
Ordering::SeqCst,
|
||||
Ordering::SeqCst,
|
||||
) {
|
||||
Ok(status) => {
|
||||
debug_assert_eq!(
|
||||
status, INCOMPLETE,
|
||||
"if compare_exchange succeeded, previous status must be incomplete",
|
||||
);
|
||||
// We init
|
||||
// We use a guard (Finish) to catch panics caused by builder
|
||||
let mut finish = Finish {
|
||||
state: &self.state,
|
||||
panicked: true,
|
||||
};
|
||||
unsafe { *self.data.get() = Some(builder()) };
|
||||
finish.panicked = false;
|
||||
|
||||
status = COMPLETE;
|
||||
self.state.store(status, Ordering::SeqCst);
|
||||
self.state.store(COMPLETE, Ordering::SeqCst);
|
||||
|
||||
// This next line is strictly an optimization
|
||||
return self.force_get();
|
||||
// This next line is strictly an optimization
|
||||
return self.force_get();
|
||||
}
|
||||
Err(status) => status,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +109,8 @@ impl<T> Once<T> {
|
||||
match status {
|
||||
INCOMPLETE => unreachable!(),
|
||||
RUNNING => {
|
||||
// TODO(eliza): replace with `core::hint::spin_loop` once our MSRV supports it.
|
||||
#[allow(deprecated)]
|
||||
// We spin
|
||||
cpu_relax();
|
||||
status = self.state.load(Ordering::SeqCst)
|
||||
@@ -126,7 +136,12 @@ impl<T> Once<T> {
|
||||
loop {
|
||||
match self.state.load(Ordering::SeqCst) {
|
||||
INCOMPLETE => return None,
|
||||
RUNNING => cpu_relax(), // We spin
|
||||
|
||||
RUNNING => {
|
||||
// TODO(eliza): replace with `core::hint::spin_loop` once our MSRV supports it.
|
||||
#[allow(deprecated)]
|
||||
cpu_relax() // We spin
|
||||
}
|
||||
COMPLETE => return Some(self.force_get()),
|
||||
PANICKED => panic!("Once has panicked"),
|
||||
_ => unsafe { unreachable() },
|
||||
|
||||
Reference in New Issue
Block a user