Skip to content

Commit

Permalink
[SOL] remove stubs for atomics
Browse files Browse the repository at this point in the history
(Pseudo) atomics are now implemented in SBF
anza-xyz/llvm-project#23
  • Loading branch information
alessandrod authored and dmakarov committed Mar 18, 2023
1 parent 7a63590 commit ae6096d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 49 deletions.
100 changes: 52 additions & 48 deletions library/core/tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,38 +212,42 @@ fn ptr_bitops_tagging() {
assert_eq!(atom.load(SeqCst), ptr);
}

static S_FALSE: AtomicBool = AtomicBool::new(false);
static S_TRUE: AtomicBool = AtomicBool::new(true);
static S_INT: AtomicIsize = AtomicIsize::new(0);
static S_UINT: AtomicUsize = AtomicUsize::new(0);

#[test]
fn static_init() {
// Note that we're not really testing the mutability here but it's important
// on Android at the moment (#49775)
assert!(!S_FALSE.swap(true, SeqCst));
assert!(S_TRUE.swap(false, SeqCst));
assert!(S_INT.fetch_add(1, SeqCst) == 0);
assert!(S_UINT.fetch_add(1, SeqCst) == 0);
// SBF does not support mustable static data
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
mod statik {
use super::*;

static S_FALSE: AtomicBool = AtomicBool::new(false);
static S_TRUE: AtomicBool = AtomicBool::new(true);
static S_INT: AtomicIsize = AtomicIsize::new(0);
static S_UINT: AtomicUsize = AtomicUsize::new(0);

#[test]
fn static_init() {
// Note that we're not really testing the mutability here but it's important
// on Android at the moment (#49775)
assert!(!S_FALSE.swap(true, SeqCst));
assert!(S_TRUE.swap(false, SeqCst));
assert!(S_INT.fetch_add(1, SeqCst) == 0);
assert!(S_UINT.fetch_add(1, SeqCst) == 0);
}
}

#[test]
fn atomic_access_bool() {
static mut ATOMIC: AtomicBool = AtomicBool::new(false);

unsafe {
assert_eq!(*ATOMIC.get_mut(), false);
ATOMIC.store(true, SeqCst);
assert_eq!(*ATOMIC.get_mut(), true);
ATOMIC.fetch_or(false, SeqCst);
assert_eq!(*ATOMIC.get_mut(), true);
ATOMIC.fetch_and(false, SeqCst);
assert_eq!(*ATOMIC.get_mut(), false);
ATOMIC.fetch_nand(true, SeqCst);
assert_eq!(*ATOMIC.get_mut(), true);
ATOMIC.fetch_xor(true, SeqCst);
assert_eq!(*ATOMIC.get_mut(), false);
}
let mut atomic: AtomicBool = AtomicBool::new(false);

assert_eq!(*atomic.get_mut(), false);
atomic.store(true, SeqCst);
assert_eq!(*atomic.get_mut(), true);
atomic.fetch_or(false, SeqCst);
assert_eq!(*atomic.get_mut(), true);
atomic.fetch_and(false, SeqCst);
assert_eq!(*atomic.get_mut(), false);
atomic.fetch_nand(true, SeqCst);
assert_eq!(*atomic.get_mut(), true);
atomic.fetch_xor(true, SeqCst);
assert_eq!(*atomic.get_mut(), false);
}

#[test]
Expand Down Expand Up @@ -284,26 +288,26 @@ fn atomic_alignment() {
fn atomic_compare_exchange() {
use Ordering::*;

static ATOMIC: AtomicIsize = AtomicIsize::new(0);

ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed).ok();
ATOMIC.compare_exchange(0, 1, Acquire, Relaxed).ok();
ATOMIC.compare_exchange(0, 1, Release, Relaxed).ok();
ATOMIC.compare_exchange(0, 1, AcqRel, Relaxed).ok();
ATOMIC.compare_exchange(0, 1, SeqCst, Relaxed).ok();
ATOMIC.compare_exchange(0, 1, Acquire, Acquire).ok();
ATOMIC.compare_exchange(0, 1, AcqRel, Acquire).ok();
ATOMIC.compare_exchange(0, 1, SeqCst, Acquire).ok();
ATOMIC.compare_exchange(0, 1, SeqCst, SeqCst).ok();
ATOMIC.compare_exchange_weak(0, 1, Relaxed, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, Acquire, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, Release, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, Acquire, Acquire).ok();
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Acquire).ok();
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Acquire).ok();
ATOMIC.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok();
let atomic: AtomicIsize = AtomicIsize::new(0);

atomic.compare_exchange(0, 1, Relaxed, Relaxed).ok();
atomic.compare_exchange(0, 1, Acquire, Relaxed).ok();
atomic.compare_exchange(0, 1, Release, Relaxed).ok();
atomic.compare_exchange(0, 1, AcqRel, Relaxed).ok();
atomic.compare_exchange(0, 1, SeqCst, Relaxed).ok();
atomic.compare_exchange(0, 1, Acquire, Acquire).ok();
atomic.compare_exchange(0, 1, AcqRel, Acquire).ok();
atomic.compare_exchange(0, 1, SeqCst, Acquire).ok();
atomic.compare_exchange(0, 1, SeqCst, SeqCst).ok();
atomic.compare_exchange_weak(0, 1, Relaxed, Relaxed).ok();
atomic.compare_exchange_weak(0, 1, Acquire, Relaxed).ok();
atomic.compare_exchange_weak(0, 1, Release, Relaxed).ok();
atomic.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok();
atomic.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok();
atomic.compare_exchange_weak(0, 1, Acquire, Acquire).ok();
atomic.compare_exchange_weak(0, 1, AcqRel, Acquire).ok();
atomic.compare_exchange_weak(0, 1, SeqCst, Acquire).ok();
atomic.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok();
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ mod any;
mod array;
mod ascii;
mod asserting;
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
mod atomic;
mod bool;
mod cell;
Expand Down

0 comments on commit ae6096d

Please sign in to comment.