Rollup merge of #127813 - ChrisDenton:win-futex, r=joboet · model-checking/verify-rust-std@a2cf636 (original) (raw)
`@@ -15,6 +15,7 @@ pub type SmallAtomic = AtomicU8;
`
15
15
`/// Must be the underlying type of SmallAtomic
`
16
16
`pub type SmallPrimitive = u8;
`
17
17
``
``
18
`+
pub unsafe trait Futex {}
`
18
19
`pub unsafe trait Waitable {
`
19
20
`type Atomic;
`
20
21
`}
`
`@@ -24,6 +25,7 @@ macro_rules! unsafe_waitable_int {
`
24
25
`unsafe impl Waitable for $int {
`
25
26
`type Atomic = $atomic;
`
26
27
`}
`
``
28
`+
unsafe impl Futex for $atomic {}
`
27
29
`)*
`
28
30
`};
`
29
31
`}
`
`@@ -46,6 +48,7 @@ unsafe impl Waitable for *const T {
`
46
48
`unsafe impl Waitable for *mut T {
`
47
49
`type Atomic = AtomicPtr;
`
48
50
`}
`
``
51
`+
unsafe impl Futex for AtomicPtr {}
`
49
52
``
50
53
`pub fn wait_on_address<W: Waitable>(
`
51
54
`address: &W::Atomic,
`
`@@ -61,14 +64,14 @@ pub fn wait_on_address<W: Waitable>(
`
61
64
`}
`
62
65
`}
`
63
66
``
64
``
`-
pub fn wake_by_address_single(address: &T) {
`
``
67
`+
pub fn wake_by_address_single<T: Futex>(address: &T) {
`
65
68
`unsafe {
`
66
69
`let addr = ptr::from_ref(address).cast::();
`
67
70
` c::WakeByAddressSingle(addr);
`
68
71
`}
`
69
72
`}
`
70
73
``
71
``
`-
pub fn wake_by_address_all(address: &T) {
`
``
74
`+
pub fn wake_by_address_all<T: Futex>(address: &T) {
`
72
75
`unsafe {
`
73
76
`let addr = ptr::from_ref(address).cast::();
`
74
77
` c::WakeByAddressAll(addr);
`
`@@ -80,11 +83,11 @@ pub fn futex_wait<W: Waitable>(futex: &W::Atomic, expected: W, timeout: Option<D
`
80
83
`wait_on_address(futex, expected, timeout) || api::get_last_error() != WinError::TIMEOUT
`
81
84
`}
`
82
85
``
83
``
`-
pub fn futex_wake(futex: &T) -> bool {
`
``
86
`+
pub fn futex_wake<T: Futex>(futex: &T) -> bool {
`
84
87
`wake_by_address_single(futex);
`
85
88
`false
`
86
89
`}
`
87
90
``
88
``
`-
pub fn futex_wake_all(futex: &T) {
`
``
91
`+
pub fn futex_wake_all<T: Futex>(futex: &T) {
`
89
92
`wake_by_address_all(futex)
`
90
93
`}
`