Skip to content

Commit fc3d252

Browse files
alessandrodLucasSte
authored andcommitted
[SOL] remove stubs for atomics
(Pseudo) atomics are now implemented in SBF anza-xyz/llvm-project#23
1 parent a7ca891 commit fc3d252

File tree

1 file changed

+52
-48
lines changed

1 file changed

+52
-48
lines changed

library/core/tests/atomic.rs

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -212,38 +212,42 @@ fn ptr_bitops_tagging() {
212212
assert_eq!(atom.load(SeqCst), ptr);
213213
}
214214

215-
static S_FALSE: AtomicBool = AtomicBool::new(false);
216-
static S_TRUE: AtomicBool = AtomicBool::new(true);
217-
static S_INT: AtomicIsize = AtomicIsize::new(0);
218-
static S_UINT: AtomicUsize = AtomicUsize::new(0);
219-
220-
#[test]
221-
fn static_init() {
222-
// Note that we're not really testing the mutability here but it's important
223-
// on Android at the moment (#49775)
224-
assert!(!S_FALSE.swap(true, SeqCst));
225-
assert!(S_TRUE.swap(false, SeqCst));
226-
assert!(S_INT.fetch_add(1, SeqCst) == 0);
227-
assert!(S_UINT.fetch_add(1, SeqCst) == 0);
215+
// SBF does not support mustable static data
216+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
217+
mod statik {
218+
use super::*;
219+
220+
static S_FALSE: AtomicBool = AtomicBool::new(false);
221+
static S_TRUE: AtomicBool = AtomicBool::new(true);
222+
static S_INT: AtomicIsize = AtomicIsize::new(0);
223+
static S_UINT: AtomicUsize = AtomicUsize::new(0);
224+
225+
#[test]
226+
fn static_init() {
227+
// Note that we're not really testing the mutability here but it's important
228+
// on Android at the moment (#49775)
229+
assert!(!S_FALSE.swap(true, SeqCst));
230+
assert!(S_TRUE.swap(false, SeqCst));
231+
assert!(S_INT.fetch_add(1, SeqCst) == 0);
232+
assert!(S_UINT.fetch_add(1, SeqCst) == 0);
233+
}
228234
}
229235

230236
#[test]
231237
fn atomic_access_bool() {
232-
static mut ATOMIC: AtomicBool = AtomicBool::new(false);
233-
234-
unsafe {
235-
assert_eq!(*ATOMIC.get_mut(), false);
236-
ATOMIC.store(true, SeqCst);
237-
assert_eq!(*ATOMIC.get_mut(), true);
238-
ATOMIC.fetch_or(false, SeqCst);
239-
assert_eq!(*ATOMIC.get_mut(), true);
240-
ATOMIC.fetch_and(false, SeqCst);
241-
assert_eq!(*ATOMIC.get_mut(), false);
242-
ATOMIC.fetch_nand(true, SeqCst);
243-
assert_eq!(*ATOMIC.get_mut(), true);
244-
ATOMIC.fetch_xor(true, SeqCst);
245-
assert_eq!(*ATOMIC.get_mut(), false);
246-
}
238+
let mut atomic: AtomicBool = AtomicBool::new(false);
239+
240+
assert_eq!(*atomic.get_mut(), false);
241+
atomic.store(true, SeqCst);
242+
assert_eq!(*atomic.get_mut(), true);
243+
atomic.fetch_or(false, SeqCst);
244+
assert_eq!(*atomic.get_mut(), true);
245+
atomic.fetch_and(false, SeqCst);
246+
assert_eq!(*atomic.get_mut(), false);
247+
atomic.fetch_nand(true, SeqCst);
248+
assert_eq!(*atomic.get_mut(), true);
249+
atomic.fetch_xor(true, SeqCst);
250+
assert_eq!(*atomic.get_mut(), false);
247251
}
248252

249253
#[test]
@@ -284,26 +288,26 @@ fn atomic_alignment() {
284288
fn atomic_compare_exchange() {
285289
use Ordering::*;
286290

287-
static ATOMIC: AtomicIsize = AtomicIsize::new(0);
288-
289-
ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed).ok();
290-
ATOMIC.compare_exchange(0, 1, Acquire, Relaxed).ok();
291-
ATOMIC.compare_exchange(0, 1, Release, Relaxed).ok();
292-
ATOMIC.compare_exchange(0, 1, AcqRel, Relaxed).ok();
293-
ATOMIC.compare_exchange(0, 1, SeqCst, Relaxed).ok();
294-
ATOMIC.compare_exchange(0, 1, Acquire, Acquire).ok();
295-
ATOMIC.compare_exchange(0, 1, AcqRel, Acquire).ok();
296-
ATOMIC.compare_exchange(0, 1, SeqCst, Acquire).ok();
297-
ATOMIC.compare_exchange(0, 1, SeqCst, SeqCst).ok();
298-
ATOMIC.compare_exchange_weak(0, 1, Relaxed, Relaxed).ok();
299-
ATOMIC.compare_exchange_weak(0, 1, Acquire, Relaxed).ok();
300-
ATOMIC.compare_exchange_weak(0, 1, Release, Relaxed).ok();
301-
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok();
302-
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok();
303-
ATOMIC.compare_exchange_weak(0, 1, Acquire, Acquire).ok();
304-
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Acquire).ok();
305-
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Acquire).ok();
306-
ATOMIC.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok();
291+
let atomic: AtomicIsize = AtomicIsize::new(0);
292+
293+
atomic.compare_exchange(0, 1, Relaxed, Relaxed).ok();
294+
atomic.compare_exchange(0, 1, Acquire, Relaxed).ok();
295+
atomic.compare_exchange(0, 1, Release, Relaxed).ok();
296+
atomic.compare_exchange(0, 1, AcqRel, Relaxed).ok();
297+
atomic.compare_exchange(0, 1, SeqCst, Relaxed).ok();
298+
atomic.compare_exchange(0, 1, Acquire, Acquire).ok();
299+
atomic.compare_exchange(0, 1, AcqRel, Acquire).ok();
300+
atomic.compare_exchange(0, 1, SeqCst, Acquire).ok();
301+
atomic.compare_exchange(0, 1, SeqCst, SeqCst).ok();
302+
atomic.compare_exchange_weak(0, 1, Relaxed, Relaxed).ok();
303+
atomic.compare_exchange_weak(0, 1, Acquire, Relaxed).ok();
304+
atomic.compare_exchange_weak(0, 1, Release, Relaxed).ok();
305+
atomic.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok();
306+
atomic.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok();
307+
atomic.compare_exchange_weak(0, 1, Acquire, Acquire).ok();
308+
atomic.compare_exchange_weak(0, 1, AcqRel, Acquire).ok();
309+
atomic.compare_exchange_weak(0, 1, SeqCst, Acquire).ok();
310+
atomic.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok();
307311
}
308312

309313
/* FIXME(#110395)

0 commit comments

Comments
 (0)