Rollup merge of #127807 - ChrisDenton:win-parking, r=joboet · model-checking/verify-rust-std@0299bb5 (original) (raw)

8 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -3,6 +3,11 @@ use crate::ptr::null;
3 3 use crate::sync::atomic::AtomicU32;
4 4 use crate::time::Duration;
5 5
6 +/// An atomic for use as a futex that is at least 8-bits but may be larger.
7 +pub type SmallAtomic = AtomicU32;
8 +/// Must be the underlying type of SmallAtomic
9 +pub type SmallPrimitive = u32;
10 +
6 11 pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool {
7 12 // Calculate the timeout as a relative timespec.
8 13 //
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@
11 11 use crate::sync::atomic::AtomicU32;
12 12 use crate::time::Duration;
13 13
14 +/// An atomic for use as a futex that is at least 8-bits but may be larger.
15 +pub type SmallAtomic = AtomicU32;
16 +/// Must be the underlying type of SmallAtomic
17 +pub type SmallPrimitive = u32;
18 +
14 19 /// Wait for a futex_wake operation to wake us.
15 20 ///
16 21 /// Returns directly if the futex doesn't hold the expected value.
Original file line number Diff line number Diff line change
@@ -6,6 +6,11 @@ use core::arch::wasm64 as wasm;
6 6 use crate::sync::atomic::AtomicU32;
7 7 use crate::time::Duration;
8 8
9 +/// An atomic for use as a futex that is at least 8-bits but may be larger.
10 +pub type SmallAtomic = AtomicU32;
11 +/// Must be the underlying type of SmallAtomic
12 +pub type SmallPrimitive = u32;
13 +
9 14 /// Wait for a futex_wake operation to wake us.
10 15 ///
11 16 /// Returns directly if the futex doesn't hold the expected value.
Original file line number Diff line number Diff line change
@@ -10,6 +10,11 @@ use core::sync::atomic::{
10 10 };
11 11 use core::time::Duration;
12 12
13 +/// An atomic for use as a futex that is at least 8-bits but may be larger.
14 +pub type SmallAtomic = AtomicU8;
15 +/// Must be the underlying type of SmallAtomic
16 +pub type SmallPrimitive = u8;
17 +
13 18 pub unsafe trait Waitable {
14 19 type Atomic;
15 20 }
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
1 -use crate::sync::atomic::{
2 -self,
3 -Ordering::{Acquire, Relaxed, Release},
4 -};
5 -use crate::sys::futex::{futex_wait, futex_wake};
6 -
7 -cfg_if::cfg_if! {
8 -if #[cfg(windows)] {
9 -// On Windows we can have a smol futex
10 -type Atomic = atomic::AtomicU8;
11 -type State = u8;
12 -} else {
13 -type Atomic = atomic::AtomicU32;
14 -type State = u32;
15 -}
16 -}
1 +use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
2 +use crate::sys::futex::{self, futex_wait, futex_wake};
3 +
4 +type Atomic = futex::SmallAtomic;
5 +type State = futex::SmallPrimitive;
17 6
18 7 pub struct Mutex {
19 8 futex: Atomic,
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
1 +#![forbid(unsafe_op_in_unsafe_fn)]
1 2 use crate::pin::Pin;
2 -use crate::sync::atomic::AtomicU32;
3 3 use crate::sync::atomic::Ordering::{Acquire, Release};
4 -use crate::sys::futex::{futex_wait, futex_wake};
4 +use crate::sys::futex::{self, futex_wait, futex_wake};
5 5 use crate::time::Duration;
6 6
7 -const PARKED: u32 = u32::MAX;
8 -const EMPTY: u32 = 0;
9 -const NOTIFIED: u32 = 1;
7 +type Atomic = futex::SmallAtomic;
8 +type State = futex::SmallPrimitive;
9 +
10 +const PARKED: State = State::MAX;
11 +const EMPTY: State = 0;
12 +const NOTIFIED: State = 1;
10 13
11 14 pub struct Parker {
12 -state: AtomicU32,
15 +state: Atomic,
13 16 }
14 17
15 18 // Notes about memory ordering:
@@ -36,7 +39,7 @@ impl Parker {
36 39 /// Construct the futex parker. The UNIX parker implementation
37 40 /// requires this to happen in-place.
38 41 pub unsafe fn new_in_place(parker: *mut Parker) {
39 - parker.write(Self { state: AtomicU32::new(EMPTY) });
42 +unsafe { parker.write(Self { state: Atomic::new(EMPTY) }) };
40 43 }
41 44
42 45 // Assumes this is only called by the thread that owns the Parker,
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1 1 cfg_if::cfg_if! {
2 2 if #[cfg(any(
3 + all(target_os = "windows", not(target_vendor = "win7")),
3 4 target_os = "linux",
4 5 target_os = "android",
5 6 all(target_arch = "wasm32", target_feature = "atomics"),
@@ -18,9 +19,9 @@ cfg_if::cfg_if! {
18 19 ))] {
19 20 mod id;
20 21 pub use id::Parker;
21 -} else if #[cfg(target_os = "windows")] {
22 -mod windows;
23 -pub use windows::Parker;
22 +} else if #[cfg(target_vendor = "win7")] {
23 +mod windows7;
24 +pub use windows7::Parker;
24 25 } else if #[cfg(all(target_vendor = "apple", not(miri)))] {
25 26 mod darwin;
26 27 pub use darwin::Parker;

File renamed without changes.