about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/unix/locks/mod.rs8
-rw-r--r--library/std/src/sys/unix/locks/pthread_condvar.rs (renamed from library/std/src/sys/unix/condvar.rs)8
-rw-r--r--library/std/src/sys/unix/locks/pthread_mutex.rs (renamed from library/std/src/sys/unix/mutex.rs)44
-rw-r--r--library/std/src/sys/unix/locks/pthread_remutex.rs46
-rw-r--r--library/std/src/sys/unix/locks/pthread_rwlock.rs (renamed from library/std/src/sys/unix/rwlock.rs)0
-rw-r--r--library/std/src/sys/unix/mod.rs4
-rw-r--r--library/std/src/sys_common/condvar.rs5
-rw-r--r--library/std/src/sys_common/condvar/check.rs8
-rw-r--r--library/std/src/sys_common/mutex.rs2
-rw-r--r--library/std/src/sys_common/remutex.rs2
-rw-r--r--library/std/src/sys_common/rwlock.rs2
11 files changed, 69 insertions, 60 deletions
diff --git a/library/std/src/sys/unix/locks/mod.rs b/library/std/src/sys/unix/locks/mod.rs
new file mode 100644
index 00000000000..f07a9f93b79
--- /dev/null
+++ b/library/std/src/sys/unix/locks/mod.rs
@@ -0,0 +1,8 @@
+mod pthread_condvar;
+mod pthread_mutex;
+mod pthread_remutex;
+mod pthread_rwlock;
+pub use pthread_condvar::{Condvar, MovableCondvar};
+pub use pthread_mutex::{MovableMutex, Mutex};
+pub use pthread_remutex::ReentrantMutex;
+pub use pthread_rwlock::{MovableRWLock, RWLock};
diff --git a/library/std/src/sys/unix/condvar.rs b/library/std/src/sys/unix/locks/pthread_condvar.rs
index 61261c0aa84..099aa68706f 100644
--- a/library/std/src/sys/unix/condvar.rs
+++ b/library/std/src/sys/unix/locks/pthread_condvar.rs
@@ -1,5 +1,5 @@
 use crate::cell::UnsafeCell;
-use crate::sys::mutex::{self, Mutex};
+use crate::sys::locks::{pthread_mutex, Mutex};
 use crate::time::Duration;
 
 pub struct Condvar {
@@ -79,7 +79,7 @@ impl Condvar {
 
     #[inline]
     pub unsafe fn wait(&self, mutex: &Mutex) {
-        let r = libc::pthread_cond_wait(self.inner.get(), mutex::raw(mutex));
+        let r = libc::pthread_cond_wait(self.inner.get(), pthread_mutex::raw(mutex));
         debug_assert_eq!(r, 0);
     }
 
@@ -111,7 +111,7 @@ impl Condvar {
         let timeout =
             sec.map(|s| libc::timespec { tv_sec: s, tv_nsec: nsec as _ }).unwrap_or(TIMESPEC_MAX);
 
-        let r = libc::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex), &timeout);
+        let r = libc::pthread_cond_timedwait(self.inner.get(), pthread_mutex::raw(mutex), &timeout);
         assert!(r == libc::ETIMEDOUT || r == 0);
         r == 0
     }
@@ -169,7 +169,7 @@ impl Condvar {
             .unwrap_or(TIMESPEC_MAX);
 
         // And wait!
-        let r = libc::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex), &timeout);
+        let r = libc::pthread_cond_timedwait(self.inner.get(), pthread_mutex::raw(mutex), &timeout);
         debug_assert!(r == libc::ETIMEDOUT || r == 0);
 
         // ETIMEDOUT is not a totally reliable method of determining timeout due
diff --git a/library/std/src/sys/unix/mutex.rs b/library/std/src/sys/unix/locks/pthread_mutex.rs
index 89c55eb859d..09cfa2f50ec 100644
--- a/library/std/src/sys/unix/mutex.rs
+++ b/library/std/src/sys/unix/locks/pthread_mutex.rs
@@ -90,49 +90,7 @@ impl Mutex {
     }
 }
 
-pub struct ReentrantMutex {
-    inner: UnsafeCell<libc::pthread_mutex_t>,
-}
-
-unsafe impl Send for ReentrantMutex {}
-unsafe impl Sync for ReentrantMutex {}
-
-impl ReentrantMutex {
-    pub const unsafe fn uninitialized() -> ReentrantMutex {
-        ReentrantMutex { inner: UnsafeCell::new(libc::PTHREAD_MUTEX_INITIALIZER) }
-    }
-
-    pub unsafe fn init(&self) {
-        let mut attr = MaybeUninit::<libc::pthread_mutexattr_t>::uninit();
-        cvt_nz(libc::pthread_mutexattr_init(attr.as_mut_ptr())).unwrap();
-        let attr = PthreadMutexAttr(&mut attr);
-        cvt_nz(libc::pthread_mutexattr_settype(attr.0.as_mut_ptr(), libc::PTHREAD_MUTEX_RECURSIVE))
-            .unwrap();
-        cvt_nz(libc::pthread_mutex_init(self.inner.get(), attr.0.as_ptr())).unwrap();
-    }
-
-    pub unsafe fn lock(&self) {
-        let result = libc::pthread_mutex_lock(self.inner.get());
-        debug_assert_eq!(result, 0);
-    }
-
-    #[inline]
-    pub unsafe fn try_lock(&self) -> bool {
-        libc::pthread_mutex_trylock(self.inner.get()) == 0
-    }
-
-    pub unsafe fn unlock(&self) {
-        let result = libc::pthread_mutex_unlock(self.inner.get());
-        debug_assert_eq!(result, 0);
-    }
-
-    pub unsafe fn destroy(&self) {
-        let result = libc::pthread_mutex_destroy(self.inner.get());
-        debug_assert_eq!(result, 0);
-    }
-}
-
-struct PthreadMutexAttr<'a>(&'a mut MaybeUninit<libc::pthread_mutexattr_t>);
+pub(super) struct PthreadMutexAttr<'a>(pub &'a mut MaybeUninit<libc::pthread_mutexattr_t>);
 
 impl Drop for PthreadMutexAttr<'_> {
     fn drop(&mut self) {
diff --git a/library/std/src/sys/unix/locks/pthread_remutex.rs b/library/std/src/sys/unix/locks/pthread_remutex.rs
new file mode 100644
index 00000000000..b006181ee3a
--- /dev/null
+++ b/library/std/src/sys/unix/locks/pthread_remutex.rs
@@ -0,0 +1,46 @@
+use super::pthread_mutex::PthreadMutexAttr;
+use crate::cell::UnsafeCell;
+use crate::mem::MaybeUninit;
+use crate::sys::cvt_nz;
+
+pub struct ReentrantMutex {
+    inner: UnsafeCell<libc::pthread_mutex_t>,
+}
+
+unsafe impl Send for ReentrantMutex {}
+unsafe impl Sync for ReentrantMutex {}
+
+impl ReentrantMutex {
+    pub const unsafe fn uninitialized() -> ReentrantMutex {
+        ReentrantMutex { inner: UnsafeCell::new(libc::PTHREAD_MUTEX_INITIALIZER) }
+    }
+
+    pub unsafe fn init(&self) {
+        let mut attr = MaybeUninit::<libc::pthread_mutexattr_t>::uninit();
+        cvt_nz(libc::pthread_mutexattr_init(attr.as_mut_ptr())).unwrap();
+        let attr = PthreadMutexAttr(&mut attr);
+        cvt_nz(libc::pthread_mutexattr_settype(attr.0.as_mut_ptr(), libc::PTHREAD_MUTEX_RECURSIVE))
+            .unwrap();
+        cvt_nz(libc::pthread_mutex_init(self.inner.get(), attr.0.as_ptr())).unwrap();
+    }
+
+    pub unsafe fn lock(&self) {
+        let result = libc::pthread_mutex_lock(self.inner.get());
+        debug_assert_eq!(result, 0);
+    }
+
+    #[inline]
+    pub unsafe fn try_lock(&self) -> bool {
+        libc::pthread_mutex_trylock(self.inner.get()) == 0
+    }
+
+    pub unsafe fn unlock(&self) {
+        let result = libc::pthread_mutex_unlock(self.inner.get());
+        debug_assert_eq!(result, 0);
+    }
+
+    pub unsafe fn destroy(&self) {
+        let result = libc::pthread_mutex_destroy(self.inner.get());
+        debug_assert_eq!(result, 0);
+    }
+}
diff --git a/library/std/src/sys/unix/rwlock.rs b/library/std/src/sys/unix/locks/pthread_rwlock.rs
index 1318c5b8e3a..1318c5b8e3a 100644
--- a/library/std/src/sys/unix/rwlock.rs
+++ b/library/std/src/sys/unix/locks/pthread_rwlock.rs
diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs
index 605cc499b3c..d5250bde75e 100644
--- a/library/std/src/sys/unix/mod.rs
+++ b/library/std/src/sys/unix/mod.rs
@@ -14,7 +14,6 @@ pub mod android;
 pub mod args;
 #[path = "../unix/cmath.rs"]
 pub mod cmath;
-pub mod condvar;
 pub mod env;
 pub mod fd;
 pub mod fs;
@@ -24,8 +23,8 @@ pub mod io;
 pub mod kernel_copy;
 #[cfg(target_os = "l4re")]
 mod l4re;
+pub mod locks;
 pub mod memchr;
-pub mod mutex;
 #[cfg(not(target_os = "l4re"))]
 pub mod net;
 #[cfg(target_os = "l4re")]
@@ -36,7 +35,6 @@ pub mod path;
 pub mod pipe;
 pub mod process;
 pub mod rand;
-pub mod rwlock;
 pub mod stack_overflow;
 pub mod stdio;
 pub mod thread;
diff --git a/library/std/src/sys_common/condvar.rs b/library/std/src/sys_common/condvar.rs
index 2c02e1cd33c..67d4b126209 100644
--- a/library/std/src/sys_common/condvar.rs
+++ b/library/std/src/sys_common/condvar.rs
@@ -1,11 +1,10 @@
-use crate::sys::condvar as imp;
-use crate::sys::mutex as mutex_imp;
+use crate::sys::locks as imp;
 use crate::sys_common::mutex::MovableMutex;
 use crate::time::Duration;
 
 mod check;
 
-type CondvarCheck = <mutex_imp::MovableMutex as check::CondvarCheck>::Check;
+type CondvarCheck = <imp::MovableMutex as check::CondvarCheck>::Check;
 
 /// An OS-based condition variable.
 pub struct Condvar {
diff --git a/library/std/src/sys_common/condvar/check.rs b/library/std/src/sys_common/condvar/check.rs
index 1578a2de60c..47aff060d6f 100644
--- a/library/std/src/sys_common/condvar/check.rs
+++ b/library/std/src/sys_common/condvar/check.rs
@@ -1,5 +1,5 @@
 use crate::sync::atomic::{AtomicUsize, Ordering};
-use crate::sys::mutex as mutex_imp;
+use crate::sys::locks as imp;
 use crate::sys_common::mutex::MovableMutex;
 
 pub trait CondvarCheck {
@@ -8,7 +8,7 @@ pub trait CondvarCheck {
 
 /// For boxed mutexes, a `Condvar` will check it's only ever used with the same
 /// mutex, based on its (stable) address.
-impl CondvarCheck for Box<mutex_imp::Mutex> {
+impl CondvarCheck for Box<imp::Mutex> {
     type Check = SameMutexCheck;
 }
 
@@ -22,7 +22,7 @@ impl SameMutexCheck {
         Self { addr: AtomicUsize::new(0) }
     }
     pub fn verify(&self, mutex: &MovableMutex) {
-        let addr = mutex.raw() as *const mutex_imp::Mutex as usize;
+        let addr = mutex.raw() as *const imp::Mutex as usize;
         match self.addr.compare_exchange(0, addr, Ordering::SeqCst, Ordering::SeqCst) {
             Ok(_) => {}               // Stored the address
             Err(n) if n == addr => {} // Lost a race to store the same address
@@ -33,7 +33,7 @@ impl SameMutexCheck {
 
 /// Unboxed mutexes may move, so `Condvar` can not require its address to stay
 /// constant.
-impl CondvarCheck for mutex_imp::Mutex {
+impl CondvarCheck for imp::Mutex {
     type Check = NoCheck;
 }
 
diff --git a/library/std/src/sys_common/mutex.rs b/library/std/src/sys_common/mutex.rs
index f3e7efb955a..12a09c98605 100644
--- a/library/std/src/sys_common/mutex.rs
+++ b/library/std/src/sys_common/mutex.rs
@@ -1,4 +1,4 @@
-use crate::sys::mutex as imp;
+use crate::sys::locks as imp;
 
 /// An OS-based mutual exclusion lock, meant for use in static variables.
 ///
diff --git a/library/std/src/sys_common/remutex.rs b/library/std/src/sys_common/remutex.rs
index 475bfca9b6d..801c9c28dd3 100644
--- a/library/std/src/sys_common/remutex.rs
+++ b/library/std/src/sys_common/remutex.rs
@@ -5,7 +5,7 @@ use crate::marker::PhantomPinned;
 use crate::ops::Deref;
 use crate::panic::{RefUnwindSafe, UnwindSafe};
 use crate::pin::Pin;
-use crate::sys::mutex as sys;
+use crate::sys::locks as sys;
 
 /// A re-entrant mutual exclusion
 ///
diff --git a/library/std/src/sys_common/rwlock.rs b/library/std/src/sys_common/rwlock.rs
index 07ec20f4dc6..eaee6312701 100644
--- a/library/std/src/sys_common/rwlock.rs
+++ b/library/std/src/sys_common/rwlock.rs
@@ -1,4 +1,4 @@
-use crate::sys::rwlock as imp;
+use crate::sys::locks as imp;
 
 /// An OS-based reader-writer lock, meant for use in static variables.
 ///