futex text: avoid spurious non-atomic reads
This commit is contained in:
parent
f15b5637f2
commit
d3a82817e2
1 changed files with 13 additions and 13 deletions
|
|
@ -2,7 +2,7 @@
|
|||
//@compile-flags: -Zmiri-disable-isolation
|
||||
|
||||
use std::mem::MaybeUninit;
|
||||
use std::ptr;
|
||||
use std::ptr::{self, addr_of};
|
||||
use std::sync::atomic::AtomicI32;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
|
|
@ -13,7 +13,7 @@ fn wake_nobody() {
|
|||
|
||||
// Wake 1 waiter. Expect zero waiters woken up, as nobody is waiting.
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(libc::SYS_futex, &futex as *const i32, libc::FUTEX_WAKE, 1), 0);
|
||||
assert_eq!(libc::syscall(libc::SYS_futex, addr_of!(futex), libc::FUTEX_WAKE, 1), 0);
|
||||
}
|
||||
|
||||
// Same, but without omitting the unused arguments.
|
||||
|
|
@ -21,7 +21,7 @@ fn wake_nobody() {
|
|||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
addr_of!(futex),
|
||||
libc::FUTEX_WAKE,
|
||||
1,
|
||||
ptr::null::<libc::timespec>(),
|
||||
|
|
@ -52,7 +52,7 @@ fn wait_wrong_val() {
|
|||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
addr_of!(futex),
|
||||
libc::FUTEX_WAIT,
|
||||
456,
|
||||
ptr::null::<libc::timespec>(),
|
||||
|
|
@ -73,7 +73,7 @@ fn wait_timeout() {
|
|||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
addr_of!(futex),
|
||||
libc::FUTEX_WAIT,
|
||||
123,
|
||||
&libc::timespec { tv_sec: 0, tv_nsec: 200_000_000 },
|
||||
|
|
@ -110,7 +110,7 @@ fn wait_absolute_timeout() {
|
|||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
addr_of!(futex),
|
||||
libc::FUTEX_WAIT_BITSET,
|
||||
123,
|
||||
&timeout,
|
||||
|
|
@ -136,7 +136,7 @@ fn wait_wake() {
|
|||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
addr_of!(FUTEX),
|
||||
libc::FUTEX_WAKE,
|
||||
10, // Wake up at most 10 threads.
|
||||
),
|
||||
|
|
@ -149,7 +149,7 @@ fn wait_wake() {
|
|||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
addr_of!(FUTEX),
|
||||
libc::FUTEX_WAIT,
|
||||
0,
|
||||
ptr::null::<libc::timespec>(),
|
||||
|
|
@ -173,7 +173,7 @@ fn wait_wake_bitset() {
|
|||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
addr_of!(FUTEX),
|
||||
libc::FUTEX_WAKE_BITSET,
|
||||
10, // Wake up at most 10 threads.
|
||||
ptr::null::<libc::timespec>(),
|
||||
|
|
@ -188,7 +188,7 @@ fn wait_wake_bitset() {
|
|||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
addr_of!(FUTEX),
|
||||
libc::FUTEX_WAKE_BITSET,
|
||||
10, // Wake up at most 10 threads.
|
||||
ptr::null::<libc::timespec>(),
|
||||
|
|
@ -204,7 +204,7 @@ fn wait_wake_bitset() {
|
|||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
addr_of!(FUTEX),
|
||||
libc::FUTEX_WAIT_BITSET,
|
||||
0,
|
||||
ptr::null::<libc::timespec>(),
|
||||
|
|
@ -244,7 +244,7 @@ fn concurrent_wait_wake() {
|
|||
unsafe {
|
||||
let ret = libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const AtomicI32,
|
||||
addr_of!(FUTEX),
|
||||
libc::FUTEX_WAIT,
|
||||
HELD,
|
||||
ptr::null::<libc::timespec>(),
|
||||
|
|
@ -267,7 +267,7 @@ fn concurrent_wait_wake() {
|
|||
FUTEX.store(FREE, Ordering::Relaxed);
|
||||
unsafe {
|
||||
DATA = 1;
|
||||
libc::syscall(libc::SYS_futex, &FUTEX as *const AtomicI32, libc::FUTEX_WAKE, 1);
|
||||
libc::syscall(libc::SYS_futex, addr_of!(FUTEX), libc::FUTEX_WAKE, 1);
|
||||
}
|
||||
|
||||
t.join().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue