-
Notifications
You must be signed in to change notification settings - Fork 275
Closed
Description
In lib.rs file
https://github.com/rust-lang/log/blob/master/src/lib.rs#L421
I find this snippet:
#[cfg(not(target_has_atomic = "ptr"))]
impl AtomicUsize {
const fn new(v: usize) -> AtomicUsize {
AtomicUsize { v: Cell::new(v) }
}
fn load(&self, _order: Ordering) -> usize {
self.v.get()
}
fn store(&self, val: usize, _order: Ordering) {
self.v.set(val)
}
#[cfg(target_has_atomic = "ptr")]
fn compare_exchange(
&self,
current: usize,
new: usize,
_success: Ordering,
_failure: Ordering,
) -> Result<usize, usize> {
let prev = self.v.get();
if current == prev {
self.v.set(new);
}
Ok(prev)
}
}
the thing confusing me is that the first cfg takes effect when target_has_atomic = "ptr" is false, then in the impl scope, compare_exchange function will never be compiled because it needs target_has_atomic="ptr" be true.
Am I right?
Metadata
Metadata
Assignees
Labels
No labels