about summary refs log tree commit diff
path: root/library/std/src/sys/windows
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-12 01:31:39 +0000
committerbors <bors@rust-lang.org>2022-11-12 01:31:39 +0000
commitb0c6527912cee113b29a33d7db0e801a58a94de5 (patch)
treebf37c6e6c71262c0f2602f842a761880b2d46c2d /library/std/src/sys/windows
parent42325c525b9d3885847a3f803abe53c562d289da (diff)
parentf30614a08877fac8c78113bd7823e1f4c9d20633 (diff)
downloadrust-b0c6527912cee113b29a33d7db0e801a58a94de5.tar.gz
rust-b0c6527912cee113b29a33d7db0e801a58a94de5.zip
Auto merge of #103150 - joboet:remove_lock_wrappers, r=m-ou-se
Remove lock wrappers in `sys_common`

This moves the lazy allocation to `sys` (SGX and UNIX). While this leads to a bit more verbosity, it will simplify future improvements by making room in `sys_common` for platform-independent implementations.

This also removes the condvar check on SGX as it is not necessary for soundness and will be removed anyway once mutex has been made movable.

For simplicity's sake, `libunwind` also uses lazy allocation now on SGX. This will require an update to the C definitions before merging this (CC `@raoulstrackx).`

r? `@m-ou-se`
Diffstat (limited to 'library/std/src/sys/windows')
-rw-r--r--library/std/src/sys/windows/locks/condvar.rs10
-rw-r--r--library/std/src/sys/windows/locks/mod.rs6
-rw-r--r--library/std/src/sys/windows/locks/mutex.rs13
-rw-r--r--library/std/src/sys/windows/locks/rwlock.rs18
4 files changed, 21 insertions, 26 deletions
diff --git a/library/std/src/sys/windows/locks/condvar.rs b/library/std/src/sys/windows/locks/condvar.rs
index be9a2abbe35..66fafa2c00b 100644
--- a/library/std/src/sys/windows/locks/condvar.rs
+++ b/library/std/src/sys/windows/locks/condvar.rs
@@ -8,8 +8,6 @@ pub struct Condvar {
     inner: UnsafeCell<c::CONDITION_VARIABLE>,
 }
 
-pub type MovableCondvar = Condvar;
-
 unsafe impl Send for Condvar {}
 unsafe impl Sync for Condvar {}
 
@@ -41,12 +39,12 @@ impl Condvar {
     }
 
     #[inline]
-    pub unsafe fn notify_one(&self) {
-        c::WakeConditionVariable(self.inner.get())
+    pub fn notify_one(&self) {
+        unsafe { c::WakeConditionVariable(self.inner.get()) }
     }
 
     #[inline]
-    pub unsafe fn notify_all(&self) {
-        c::WakeAllConditionVariable(self.inner.get())
+    pub fn notify_all(&self) {
+        unsafe { c::WakeAllConditionVariable(self.inner.get()) }
     }
 }
diff --git a/library/std/src/sys/windows/locks/mod.rs b/library/std/src/sys/windows/locks/mod.rs
index 602a2d6231a..0e0f9eccb21 100644
--- a/library/std/src/sys/windows/locks/mod.rs
+++ b/library/std/src/sys/windows/locks/mod.rs
@@ -1,6 +1,6 @@
 mod condvar;
 mod mutex;
 mod rwlock;
-pub use condvar::{Condvar, MovableCondvar};
-pub use mutex::{MovableMutex, Mutex};
-pub use rwlock::MovableRwLock;
+pub use condvar::Condvar;
+pub use mutex::Mutex;
+pub use rwlock::RwLock;
diff --git a/library/std/src/sys/windows/locks/mutex.rs b/library/std/src/sys/windows/locks/mutex.rs
index 91207f5f466..ef2f84082cd 100644
--- a/library/std/src/sys/windows/locks/mutex.rs
+++ b/library/std/src/sys/windows/locks/mutex.rs
@@ -21,9 +21,6 @@ pub struct Mutex {
     srwlock: UnsafeCell<c::SRWLOCK>,
 }
 
-// Windows SRW Locks are movable (while not borrowed).
-pub type MovableMutex = Mutex;
-
 unsafe impl Send for Mutex {}
 unsafe impl Sync for Mutex {}
 
@@ -39,13 +36,15 @@ impl Mutex {
     }
 
     #[inline]
-    pub unsafe fn lock(&self) {
-        c::AcquireSRWLockExclusive(raw(self));
+    pub fn lock(&self) {
+        unsafe {
+            c::AcquireSRWLockExclusive(raw(self));
+        }
     }
 
     #[inline]
-    pub unsafe fn try_lock(&self) -> bool {
-        c::TryAcquireSRWLockExclusive(raw(self)) != 0
+    pub fn try_lock(&self) -> bool {
+        unsafe { c::TryAcquireSRWLockExclusive(raw(self)) != 0 }
     }
 
     #[inline]
diff --git a/library/std/src/sys/windows/locks/rwlock.rs b/library/std/src/sys/windows/locks/rwlock.rs
index fa5ffe5749f..e69415baac4 100644
--- a/library/std/src/sys/windows/locks/rwlock.rs
+++ b/library/std/src/sys/windows/locks/rwlock.rs
@@ -5,8 +5,6 @@ pub struct RwLock {
     inner: UnsafeCell<c::SRWLOCK>,
 }
 
-pub type MovableRwLock = RwLock;
-
 unsafe impl Send for RwLock {}
 unsafe impl Sync for RwLock {}
 
@@ -16,20 +14,20 @@ impl RwLock {
         RwLock { inner: UnsafeCell::new(c::SRWLOCK_INIT) }
     }
     #[inline]
-    pub unsafe fn read(&self) {
-        c::AcquireSRWLockShared(self.inner.get())
+    pub fn read(&self) {
+        unsafe { c::AcquireSRWLockShared(self.inner.get()) }
     }
     #[inline]
-    pub unsafe fn try_read(&self) -> bool {
-        c::TryAcquireSRWLockShared(self.inner.get()) != 0
+    pub fn try_read(&self) -> bool {
+        unsafe { c::TryAcquireSRWLockShared(self.inner.get()) != 0 }
     }
     #[inline]
-    pub unsafe fn write(&self) {
-        c::AcquireSRWLockExclusive(self.inner.get())
+    pub fn write(&self) {
+        unsafe { c::AcquireSRWLockExclusive(self.inner.get()) }
     }
     #[inline]
-    pub unsafe fn try_write(&self) -> bool {
-        c::TryAcquireSRWLockExclusive(self.inner.get()) != 0
+    pub fn try_write(&self) -> bool {
+        unsafe { c::TryAcquireSRWLockExclusive(self.inner.get()) != 0 }
     }
     #[inline]
     pub unsafe fn read_unlock(&self) {