Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita2cf636

Browse files
authored
Rollup merge ofrust-lang#127813 - ChrisDenton:win-futex, r=joboet
Prevent double reference in generic futexIn the Windows futex implementation we were a little lax at allowing references to references (i.e. `&&`) which can lead to deadlocks due to reading the wrong memory address. This uses a trait to tighten the constraints and ensure this doesn't happen.r? libs
2 parentsaeae332 +e0ea701 commita2cf636

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

‎std/src/sys/pal/windows/futex.rs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub type SmallAtomic = AtomicU8;
1515
/// Must be the underlying type of SmallAtomic
1616
pubtypeSmallPrimitive =u8;
1717

18+
pubunsafetraitFutex{}
1819
pubunsafetraitWaitable{
1920
typeAtomic;
2021
}
@@ -24,6 +25,7 @@ macro_rules! unsafe_waitable_int {
2425
unsafeimplWaitablefor $int{
2526
typeAtomic = $atomic;
2627
}
28+
unsafeimplFutexfor $atomic{}
2729
)*
2830
};
2931
}
@@ -46,6 +48,7 @@ unsafe impl<T> Waitable for *const T {
4648
unsafeimpl<T>Waitablefor*mutT{
4749
typeAtomic =AtomicPtr<T>;
4850
}
51+
unsafeimpl<T>FutexforAtomicPtr<T>{}
4952

5053
pubfnwait_on_address<W:Waitable>(
5154
address:&W::Atomic,
@@ -61,14 +64,14 @@ pub fn wait_on_address<W: Waitable>(
6164
}
6265
}
6366

64-
pubfnwake_by_address_single<T>(address:&T){
67+
pubfnwake_by_address_single<T:Futex>(address:&T){
6568
unsafe{
6669
let addr = ptr::from_ref(address).cast::<c_void>();
6770
c::WakeByAddressSingle(addr);
6871
}
6972
}
7073

71-
pubfnwake_by_address_all<T>(address:&T){
74+
pubfnwake_by_address_all<T:Futex>(address:&T){
7275
unsafe{
7376
let addr = ptr::from_ref(address).cast::<c_void>();
7477
c::WakeByAddressAll(addr);
@@ -80,11 +83,11 @@ pub fn futex_wait<W: Waitable>(futex: &W::Atomic, expected: W, timeout: Option<D
8083
wait_on_address(futex, expected, timeout) || api::get_last_error() !=WinError::TIMEOUT
8184
}
8285

83-
pubfnfutex_wake<T>(futex:&T) ->bool{
86+
pubfnfutex_wake<T:Futex>(futex:&T) ->bool{
8487
wake_by_address_single(futex);
8588
false
8689
}
8790

88-
pubfnfutex_wake_all<T>(futex:&T){
91+
pubfnfutex_wake_all<T:Futex>(futex:&T){
8992
wake_by_address_all(futex)
9093
}

‎std/src/sys/sync/once/futex.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'a> Drop for CompletionGuard<'a> {
5757
// up on the Once. `futex_wake_all` does its own synchronization, hence
5858
// we do not need `AcqRel`.
5959
ifself.state.swap(self.set_state_on_drop_to,Release) ==QUEUED{
60-
futex_wake_all(&self.state);
60+
futex_wake_all(self.state);
6161
}
6262
}
6363
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp