Skip to content

Commit 8a1e441

Browse files
committed
Wrap std atomic types in newtype
1 parent 20efe97 commit 8a1e441

File tree

14 files changed

+421
-257
lines changed

14 files changed

+421
-257
lines changed

bench/benches/imp/intrinsics.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,6 @@ macro_rules! atomic128 {
347347
v: UnsafeCell<$int_type>,
348348
}
349349

350-
impl crate::utils::AtomicRepr for $atomic_type {
351-
const IS_ALWAYS_LOCK_FREE: bool = true;
352-
#[inline]
353-
fn is_lock_free() -> bool {
354-
true
355-
}
356-
}
357-
358350
// Send is implicitly implemented.
359351
// SAFETY: any data races are prevented by atomic intrinsics.
360352
unsafe impl Sync for $atomic_type {}
@@ -365,6 +357,15 @@ macro_rules! atomic128 {
365357
Self { v: UnsafeCell::new(v) }
366358
}
367359

360+
#[inline]
361+
pub(crate) fn is_lock_free() -> bool {
362+
Self::is_always_lock_free()
363+
}
364+
#[inline]
365+
pub(crate) const fn is_always_lock_free() -> bool {
366+
true
367+
}
368+
368369
#[inline]
369370
pub(crate) fn get_mut(&mut self) -> &mut $int_type {
370371
self.v.get_mut()

bench/benches/imp/spinlock_fallback.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,6 @@ macro_rules! atomic_int {
8282
v: UnsafeCell<$int_type>,
8383
}
8484

85-
impl crate::utils::AtomicRepr for $atomic_type {
86-
const IS_ALWAYS_LOCK_FREE: bool = false;
87-
#[inline]
88-
fn is_lock_free() -> bool {
89-
false
90-
}
91-
}
92-
9385
// Send is implicitly implemented.
9486
// SAFETY: any data races are prevented by the lock.
9587
unsafe impl Sync for $atomic_type {}
@@ -100,6 +92,15 @@ macro_rules! atomic_int {
10092
Self { v: UnsafeCell::new(v) }
10193
}
10294

95+
#[inline]
96+
pub(crate) fn is_lock_free() -> bool {
97+
Self::is_always_lock_free()
98+
}
99+
#[inline]
100+
pub(crate) const fn is_always_lock_free() -> bool {
101+
false
102+
}
103+
103104
#[inline]
104105
pub(crate) fn get_mut(&mut self) -> &mut $int_type {
105106
// SAFETY: This is safe because the mutable reference guarantees that no other

src/imp/atomic128/macros.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ macro_rules! atomic128 {
55
v: core::cell::UnsafeCell<$int_type>,
66
}
77

8-
impl crate::utils::AtomicRepr for $atomic_type {
9-
const IS_ALWAYS_LOCK_FREE: bool = true;
10-
#[inline]
11-
fn is_lock_free() -> bool {
12-
true
13-
}
14-
}
15-
168
// Send is implicitly implemented.
179
// SAFETY: any data races are prevented by atomic intrinsics.
1810
unsafe impl Sync for $atomic_type {}
@@ -23,6 +15,15 @@ macro_rules! atomic128 {
2315
Self { v: core::cell::UnsafeCell::new(v) }
2416
}
2517

18+
#[inline]
19+
pub(crate) fn is_lock_free() -> bool {
20+
Self::is_always_lock_free()
21+
}
22+
#[inline]
23+
pub(crate) const fn is_always_lock_free() -> bool {
24+
true
25+
}
26+
2627
#[inline]
2728
pub(crate) fn get_mut(&mut self) -> &mut $int_type {
2829
self.v.get_mut()

src/imp/atomic128/powerpc64.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,6 @@ macro_rules! atomic128 {
754754
v: core::cell::UnsafeCell<$int_type>,
755755
}
756756

757-
impl crate::utils::AtomicRepr for $atomic_type {
758-
const IS_ALWAYS_LOCK_FREE: bool = true;
759-
#[inline]
760-
fn is_lock_free() -> bool {
761-
true
762-
}
763-
}
764-
765757
// Send is implicitly implemented.
766758
// SAFETY: any data races are prevented by atomic intrinsics.
767759
unsafe impl Sync for $atomic_type {}
@@ -772,6 +764,15 @@ macro_rules! atomic128 {
772764
Self { v: core::cell::UnsafeCell::new(v) }
773765
}
774766

767+
#[inline]
768+
pub(crate) fn is_lock_free() -> bool {
769+
Self::is_always_lock_free()
770+
}
771+
#[inline]
772+
pub(crate) const fn is_always_lock_free() -> bool {
773+
true
774+
}
775+
775776
#[inline]
776777
pub(crate) fn get_mut(&mut self) -> &mut $int_type {
777778
self.v.get_mut()

src/imp/atomic128/x86_64.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,6 @@ macro_rules! atomic128 {
408408
v: UnsafeCell<$int_type>,
409409
}
410410

411-
impl crate::utils::AtomicRepr for $atomic_type {
412-
const IS_ALWAYS_LOCK_FREE: bool = cfg!(any(
413-
target_feature = "cmpxchg16b",
414-
portable_atomic_target_feature = "cmpxchg16b",
415-
));
416-
#[inline]
417-
fn is_lock_free() -> bool {
418-
detect::has_cmpxchg16b()
419-
}
420-
}
421-
422411
// Send is implicitly implemented.
423412
// SAFETY: any data races are prevented by atomic operations.
424413
unsafe impl Sync for $atomic_type {}
@@ -429,6 +418,18 @@ macro_rules! atomic128 {
429418
Self { v: UnsafeCell::new(v) }
430419
}
431420

421+
#[inline]
422+
pub(crate) fn is_lock_free() -> bool {
423+
detect::has_cmpxchg16b()
424+
}
425+
#[inline]
426+
pub(crate) const fn is_always_lock_free() -> bool {
427+
cfg!(any(
428+
target_feature = "cmpxchg16b",
429+
portable_atomic_target_feature = "cmpxchg16b",
430+
))
431+
}
432+
432433
#[inline]
433434
pub(crate) fn get_mut(&mut self) -> &mut $int_type {
434435
self.v.get_mut()
@@ -602,7 +603,6 @@ atomic128!(AtomicU128, u128);
602603
#[cfg(test)]
603604
mod tests {
604605
use super::*;
605-
use crate::utils::AtomicRepr;
606606

607607
test_atomic_int!(i128);
608608
test_atomic_int!(u128);

0 commit comments

Comments
 (0)