2024-02-16 20:02:50 +00:00
|
|
|
//@ only-x86_64
|
2020-09-09 21:00:31 +00:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// `compare_exchange` (not weak) testing
|
|
|
|
let x = AtomicUsize::new(0);
|
|
|
|
|
|
|
|
// Allowed ordering combos
|
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Relaxed);
|
2022-07-18 00:00:00 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Acquire);
|
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::SeqCst);
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Relaxed);
|
2022-07-18 00:00:00 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Acquire);
|
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::SeqCst);
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Relaxed);
|
2022-07-18 00:00:00 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Acquire);
|
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::SeqCst);
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Relaxed);
|
2022-07-18 00:00:00 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Acquire);
|
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst);
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Relaxed);
|
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Acquire);
|
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::SeqCst);
|
|
|
|
|
|
|
|
// AcqRel is always forbidden as a failure ordering
|
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::AcqRel);
|
2022-06-22 18:03:39 +00:00
|
|
|
//~^ ERROR `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::AcqRel);
|
2022-06-22 18:03:39 +00:00
|
|
|
//~^ ERROR `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::AcqRel);
|
2022-06-22 18:03:39 +00:00
|
|
|
//~^ ERROR `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::AcqRel);
|
2022-06-22 18:03:39 +00:00
|
|
|
//~^ ERROR `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::AcqRel);
|
2022-06-22 18:03:39 +00:00
|
|
|
//~^ ERROR `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`
|
2020-09-09 21:00:31 +00:00
|
|
|
|
|
|
|
// Release is always forbidden as a failure ordering
|
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Release);
|
2022-06-22 18:03:39 +00:00
|
|
|
//~^ ERROR `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Release);
|
2022-06-22 18:03:39 +00:00
|
|
|
//~^ ERROR `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Release);
|
2022-06-22 18:03:39 +00:00
|
|
|
//~^ ERROR `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Release);
|
2022-06-22 18:03:39 +00:00
|
|
|
//~^ ERROR `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`
|
2020-09-09 21:00:31 +00:00
|
|
|
let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Release);
|
2022-06-22 18:03:39 +00:00
|
|
|
//~^ ERROR `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`
|
2020-09-09 21:00:31 +00:00
|
|
|
}
|