Move std::sys::{mutex, condvar, rwlock} to std::sys::locks.

This commit is contained in:
Mara Bos 2022-03-21 15:45:51 +01:00
parent ac6996345d
commit 733153f2e5
21 changed files with 64 additions and 40 deletions

View File

@ -2,7 +2,7 @@ use crate::ffi::c_void;
use crate::ptr;
use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use crate::sys::hermit::abi;
use crate::sys::mutex::Mutex;
use crate::sys::locks::Mutex;
use crate::time::Duration;
// The implementation is inspired by Andrew D. Birrell's paper

View File

@ -22,14 +22,12 @@ pub mod alloc;
pub mod args;
#[path = "../unix/cmath.rs"]
pub mod cmath;
pub mod condvar;
pub mod env;
pub mod fd;
pub mod fs;
#[path = "../unsupported/io.rs"]
pub mod io;
pub mod memchr;
pub mod mutex;
pub mod net;
pub mod os;
#[path = "../unix/os_str.rs"]
@ -40,7 +38,6 @@ pub mod path;
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
pub mod rwlock;
pub mod stdio;
pub mod thread;
pub mod thread_local_dtor;
@ -48,6 +45,16 @@ pub mod thread_local_dtor;
pub mod thread_local_key;
pub mod time;
mod condvar;
mod mutex;
mod rwlock;
pub mod locks {
pub use super::condvar::*;
pub use super::mutex::*;
pub use super::rwlock::*;
}
use crate::io::ErrorKind;
#[allow(unused_extern_crates)]

View File

@ -1,6 +1,5 @@
use crate::cell::UnsafeCell;
use crate::sys::condvar::Condvar;
use crate::sys::mutex::Mutex;
use crate::sys::locks::{Condvar, Mutex};
pub struct RWLock {
lock: Mutex,

View File

@ -1,6 +1,6 @@
//! POSIX conditional variable implementation based on user-space wait queues.
use super::{abi, error::expect_success_aborting, spin::SpinMutex, task, time::with_tmos_strong};
use crate::{mem::replace, ptr::NonNull, sys::mutex::Mutex, time::Duration};
use crate::{mem::replace, ptr::NonNull, sys::locks::Mutex, time::Duration};
// The implementation is inspired by the queue-based implementation shown in
// Andrew D. Birrell's paper "Implementing Condition Variables with Semaphores"

View File

@ -1,4 +1,4 @@
use crate::sys::mutex::Mutex;
use crate::sys::locks::Mutex;
use crate::time::Duration;
use super::waitqueue::{SpinMutex, WaitQueue, WaitVariable};

View File

@ -15,7 +15,6 @@ pub mod alloc;
pub mod args;
#[path = "../unix/cmath.rs"]
pub mod cmath;
pub mod condvar;
pub mod env;
pub mod fd;
#[path = "../unsupported/fs.rs"]
@ -23,7 +22,6 @@ pub mod fs;
#[path = "../unsupported/io.rs"]
pub mod io;
pub mod memchr;
pub mod mutex;
pub mod net;
pub mod os;
#[path = "../unix/os_str.rs"]
@ -33,12 +31,21 @@ pub mod path;
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
pub mod rwlock;
pub mod stdio;
pub mod thread;
pub mod thread_local_key;
pub mod time;
mod condvar;
mod mutex;
mod rwlock;
pub mod locks {
pub use super::condvar::*;
pub use super::mutex::*;
pub use super::rwlock::*;
}
// SAFETY: must be called only once during runtime initialization.
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
pub unsafe fn init(argc: isize, argv: *const *const u8) {

View File

@ -37,14 +37,21 @@ pub mod path;
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
pub mod rwlock;
pub mod stdio;
pub use self::itron::{condvar, mutex, thread};
pub use self::itron::thread;
pub mod memchr;
pub mod thread_local_dtor;
pub mod thread_local_key;
pub mod time;
mod rwlock;
pub mod locks {
pub use super::itron::condvar::*;
pub use super::itron::mutex::*;
pub use super::rwlock::*;
}
// SAFETY: must be called only once during runtime initialization.
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}

View File

@ -1,4 +1,4 @@
use crate::sys::mutex::Mutex;
use crate::sys::locks::Mutex;
use crate::time::Duration;
pub struct Condvar {}

View File

@ -0,0 +1,6 @@
mod condvar;
mod mutex;
mod rwlock;
pub use condvar::{Condvar, MovableCondvar};
pub use mutex::{MovableMutex, Mutex, ReentrantMutex};
pub use rwlock::{MovableRWLock, RWLock};

View File

@ -4,11 +4,10 @@ pub mod alloc;
pub mod args;
#[path = "../unix/cmath.rs"]
pub mod cmath;
pub mod condvar;
pub mod env;
pub mod fs;
pub mod io;
pub mod mutex;
pub mod locks;
pub mod net;
pub mod os;
#[path = "../unix/os_str.rs"]
@ -17,7 +16,6 @@ pub mod os_str;
pub mod path;
pub mod pipe;
pub mod process;
pub mod rwlock;
pub mod stdio;
pub mod thread;
#[cfg(target_thread_local)]

View File

@ -22,14 +22,12 @@ pub mod alloc;
pub mod args;
#[path = "../unix/cmath.rs"]
pub mod cmath;
#[path = "../unsupported/condvar.rs"]
pub mod condvar;
pub mod env;
pub mod fd;
pub mod fs;
pub mod io;
#[path = "../unsupported/mutex.rs"]
pub mod mutex;
#[path = "../unsupported/locks/mod.rs"]
pub mod locks;
pub mod net;
pub mod os;
#[path = "../unix/os_str.rs"]
@ -40,8 +38,6 @@ pub mod path;
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
#[path = "../unsupported/rwlock.rs"]
pub mod rwlock;
pub mod stdio;
pub mod thread;
#[path = "../unsupported/thread_local_dtor.rs"]

View File

@ -2,7 +2,7 @@ use crate::arch::wasm32;
use crate::cmp;
use crate::mem;
use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use crate::sys::mutex::Mutex;
use crate::sys::locks::Mutex;
use crate::time::Duration;
pub struct Condvar {

View File

@ -1,6 +1,5 @@
use crate::cell::UnsafeCell;
use crate::sys::condvar::Condvar;
use crate::sys::mutex::Mutex;
use crate::sys::locks::{Condvar, Mutex};
pub struct RWLock {
lock: Mutex,

View File

@ -50,22 +50,23 @@ pub mod time;
cfg_if::cfg_if! {
if #[cfg(target_feature = "atomics")] {
#[path = "atomics/condvar.rs"]
pub mod condvar;
mod condvar;
#[path = "atomics/mutex.rs"]
pub mod mutex;
mod mutex;
#[path = "atomics/rwlock.rs"]
pub mod rwlock;
mod rwlock;
pub mod locks {
pub use super::condvar::*;
pub use super::mutex::*;
pub use super::rwlock::*;
}
#[path = "atomics/futex.rs"]
pub mod futex;
#[path = "atomics/thread.rs"]
pub mod thread;
} else {
#[path = "../unsupported/condvar.rs"]
pub mod condvar;
#[path = "../unsupported/mutex.rs"]
pub mod mutex;
#[path = "../unsupported/rwlock.rs"]
pub mod rwlock;
#[path = "../unsupported/locks/mod.rs"]
pub mod locks;
#[path = "../unsupported/thread.rs"]
pub mod thread;
}

View File

@ -1,6 +1,6 @@
use crate::cell::UnsafeCell;
use crate::sys::c;
use crate::sys::mutex::{self, Mutex};
use crate::sys::locks::{mutex, Mutex};
use crate::sys::os;
use crate::time::Duration;
@ -31,7 +31,7 @@ impl Condvar {
let r = c::SleepConditionVariableSRW(
self.inner.get(),
mutex::raw(mutex),
super::dur2timeout(dur),
crate::sys::windows::dur2timeout(dur),
0,
);
if r == 0 {

View File

@ -0,0 +1,6 @@
mod condvar;
mod mutex;
mod rwlock;
pub use condvar::{Condvar, MovableCondvar};
pub use mutex::{MovableMutex, Mutex, ReentrantMutex};
pub use rwlock::{MovableRWLock, RWLock};

View File

@ -16,13 +16,12 @@ pub mod alloc;
pub mod args;
pub mod c;
pub mod cmath;
pub mod condvar;
pub mod env;
pub mod fs;
pub mod handle;
pub mod io;
pub mod locks;
pub mod memchr;
pub mod mutex;
pub mod net;
pub mod os;
pub mod os_str;
@ -30,7 +29,6 @@ pub mod path;
pub mod pipe;
pub mod process;
pub mod rand;
pub mod rwlock;
pub mod thread;
pub mod thread_local_dtor;
pub mod thread_local_key;