diff options
| author | bors <bors@rust-lang.org> | 2020-10-04 06:48:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-10-04 06:48:17 +0000 |
| commit | 32cbc65e6bf793d99dc609d11f4a4c93176cdbe2 (patch) | |
| tree | 63c17253897262e610c61eb3c67144edf0da4186 /library/std/src/sys/windows | |
| parent | 2251766944f355a039e67aeb13ab630b2d46bf9b (diff) | |
| parent | b1ce7a38a6c03ddff23ef7e59e74cab6452ed9b0 (diff) | |
| download | rust-32cbc65e6bf793d99dc609d11f4a4c93176cdbe2.tar.gz rust-32cbc65e6bf793d99dc609d11f4a4c93176cdbe2.zip | |
Auto merge of #77380 - fusion-engineering-forks:unbox-the-mutex, r=dtolnay
Unbox mutexes and condvars on some platforms Both mutexes and condition variables contained a Box containing the actual os-specific object. This was done because moving these objects may cause undefined behaviour on some platforms. However, this is not needed on Windows[1], Wasm[2], cloudabi[2], and 'unsupported'[3], were the box was only needlessly making them less efficient. This change gets rid of the box on those platforms. On those platforms, `Condvar` can no longer verify it is only used with one `Mutex`, as mutexes no longer have a stable address. This was addressed and considered acceptable in #76932. [1]\: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initializesrwlock [2]\: These are just a single atomic integer together with futex wait/wake calls/instructions. [3]\: The `unsupported` platform doesn't support multiple threads at all.
Diffstat (limited to 'library/std/src/sys/windows')
| -rw-r--r-- | library/std/src/sys/windows/condvar.rs | 2 | ||||
| -rw-r--r-- | library/std/src/sys/windows/mutex.rs | 5 |
2 files changed, 7 insertions, 0 deletions
diff --git a/library/std/src/sys/windows/condvar.rs b/library/std/src/sys/windows/condvar.rs index 8f7f6854cc2..44547a5c51a 100644 --- a/library/std/src/sys/windows/condvar.rs +++ b/library/std/src/sys/windows/condvar.rs @@ -8,6 +8,8 @@ pub struct Condvar { inner: UnsafeCell<c::CONDITION_VARIABLE>, } +pub type MovableCondvar = Condvar; + unsafe impl Send for Condvar {} unsafe impl Sync for Condvar {} diff --git a/library/std/src/sys/windows/mutex.rs b/library/std/src/sys/windows/mutex.rs index e2aaca59fe2..fa51b006c34 100644 --- a/library/std/src/sys/windows/mutex.rs +++ b/library/std/src/sys/windows/mutex.rs @@ -29,6 +29,11 @@ pub struct Mutex { lock: AtomicUsize, } +// Windows SRW Locks are movable (while not borrowed). +// ReentrantMutexes (in Inner) are not, but those are stored indirectly through +// a Box, so do not move when the Mutex it self is moved. +pub type MovableMutex = Mutex; + unsafe impl Send for Mutex {} unsafe impl Sync for Mutex {} |
