about summary refs log tree commit diff
path: root/library/std/src/sys/unsupported
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/unsupported
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/unsupported')
-rw-r--r--library/std/src/sys/unsupported/locks/condvar.rs6
-rw-r--r--library/std/src/sys/unsupported/locks/mod.rs6
-rw-r--r--library/std/src/sys/unsupported/locks/mutex.rs6
-rw-r--r--library/std/src/sys/unsupported/locks/rwlock.rs10
4 files changed, 11 insertions, 17 deletions
diff --git a/library/std/src/sys/unsupported/locks/condvar.rs b/library/std/src/sys/unsupported/locks/condvar.rs
index 527a26a12bc..3f0943b50ee 100644
--- a/library/std/src/sys/unsupported/locks/condvar.rs
+++ b/library/std/src/sys/unsupported/locks/condvar.rs
@@ -3,8 +3,6 @@ use crate::time::Duration;
 
 pub struct Condvar {}
 
-pub type MovableCondvar = Condvar;
-
 impl Condvar {
     #[inline]
     #[rustc_const_stable(feature = "const_locks", since = "1.63.0")]
@@ -13,10 +11,10 @@ impl Condvar {
     }
 
     #[inline]
-    pub unsafe fn notify_one(&self) {}
+    pub fn notify_one(&self) {}
 
     #[inline]
-    pub unsafe fn notify_all(&self) {}
+    pub fn notify_all(&self) {}
 
     pub unsafe fn wait(&self, _mutex: &Mutex) {
         panic!("condvar wait not supported")
diff --git a/library/std/src/sys/unsupported/locks/mod.rs b/library/std/src/sys/unsupported/locks/mod.rs
index 602a2d6231a..0e0f9eccb21 100644
--- a/library/std/src/sys/unsupported/locks/mod.rs
+++ b/library/std/src/sys/unsupported/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/unsupported/locks/mutex.rs b/library/std/src/sys/unsupported/locks/mutex.rs
index 87ea475c6e3..4a13c55fb8b 100644
--- a/library/std/src/sys/unsupported/locks/mutex.rs
+++ b/library/std/src/sys/unsupported/locks/mutex.rs
@@ -5,8 +5,6 @@ pub struct Mutex {
     locked: Cell<bool>,
 }
 
-pub type MovableMutex = Mutex;
-
 unsafe impl Send for Mutex {}
 unsafe impl Sync for Mutex {} // no threads on this platform
 
@@ -18,7 +16,7 @@ impl Mutex {
     }
 
     #[inline]
-    pub unsafe fn lock(&self) {
+    pub fn lock(&self) {
         assert_eq!(self.locked.replace(true), false, "cannot recursively acquire mutex");
     }
 
@@ -28,7 +26,7 @@ impl Mutex {
     }
 
     #[inline]
-    pub unsafe fn try_lock(&self) -> bool {
+    pub fn try_lock(&self) -> bool {
         self.locked.replace(true) == false
     }
 }
diff --git a/library/std/src/sys/unsupported/locks/rwlock.rs b/library/std/src/sys/unsupported/locks/rwlock.rs
index 5292691b955..789ef9b29e5 100644
--- a/library/std/src/sys/unsupported/locks/rwlock.rs
+++ b/library/std/src/sys/unsupported/locks/rwlock.rs
@@ -5,8 +5,6 @@ pub struct RwLock {
     mode: Cell<isize>,
 }
 
-pub type MovableRwLock = RwLock;
-
 unsafe impl Send for RwLock {}
 unsafe impl Sync for RwLock {} // no threads on this platform
 
@@ -18,7 +16,7 @@ impl RwLock {
     }
 
     #[inline]
-    pub unsafe fn read(&self) {
+    pub fn read(&self) {
         let m = self.mode.get();
         if m >= 0 {
             self.mode.set(m + 1);
@@ -28,7 +26,7 @@ impl RwLock {
     }
 
     #[inline]
-    pub unsafe fn try_read(&self) -> bool {
+    pub fn try_read(&self) -> bool {
         let m = self.mode.get();
         if m >= 0 {
             self.mode.set(m + 1);
@@ -39,14 +37,14 @@ impl RwLock {
     }
 
     #[inline]
-    pub unsafe fn write(&self) {
+    pub fn write(&self) {
         if self.mode.replace(-1) != 0 {
             rtabort!("rwlock locked for reading")
         }
     }
 
     #[inline]
-    pub unsafe fn try_write(&self) -> bool {
+    pub fn try_write(&self) -> bool {
         if self.mode.get() == 0 {
             self.mode.set(-1);
             true