Skip to content

Commit aabb609

Browse files
committed
std: move locks to sys on UNIX and other futex platforms
1 parent 653f7b5 commit aabb609

File tree

15 files changed

+55
-218
lines changed

15 files changed

+55
-218
lines changed

std/src/sys/pal/unix/locks/futex_condvar.rs renamed to std/src/sys/locks/condvar/futex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use super::Mutex;
21
use crate::sync::atomic::{AtomicU32, Ordering::Relaxed};
32
use crate::sys::futex::{futex_wait, futex_wake, futex_wake_all};
3+
use crate::sys::locks::Mutex;
44
use crate::time::Duration;
55

66
pub struct Condvar {

std/src/sys/locks/condvar/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
cfg_if::cfg_if! {
2-
if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
2+
if #[cfg(any(
3+
target_os = "linux",
4+
target_os = "android",
5+
target_os = "freebsd",
6+
target_os = "openbsd",
7+
target_os = "dragonfly",
8+
target_os = "fuchsia",
9+
all(target_family = "wasm", target_feature = "atomics"),
10+
target_os = "hermit",
11+
))] {
12+
mod futex;
13+
pub use futex::Condvar;
14+
} else if #[cfg(target_family = "unix")] {
15+
mod pthread;
16+
pub use pthread::Condvar;
17+
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
318
mod sgx;
419
pub use sgx::Condvar;
520
} else if #[cfg(target_os = "solid_asp3")] {

std/src/sys/pal/unix/locks/pthread_condvar.rs renamed to std/src/sys/locks/condvar/pthread.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::cell::UnsafeCell;
22
use crate::ptr;
33
use crate::sync::atomic::{AtomicPtr, Ordering::Relaxed};
4-
use crate::sys::locks::{pthread_mutex, Mutex};
4+
use crate::sys::locks::{mutex, Mutex};
55
#[cfg(not(target_os = "nto"))]
66
use crate::sys::time::TIMESPEC_MAX;
77
#[cfg(target_os = "nto")]
@@ -112,7 +112,7 @@ impl Condvar {
112112

113113
#[inline]
114114
pub unsafe fn wait(&self, mutex: &Mutex) {
115-
let mutex = pthread_mutex::raw(mutex);
115+
let mutex = mutex::raw(mutex);
116116
self.verify(mutex);
117117
let r = libc::pthread_cond_wait(raw(self), mutex);
118118
debug_assert_eq!(r, 0);
@@ -134,7 +134,7 @@ impl Condvar {
134134
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
135135
use crate::sys::time::Timespec;
136136

137-
let mutex = pthread_mutex::raw(mutex);
137+
let mutex = mutex::raw(mutex);
138138
self.verify(mutex);
139139

140140
#[cfg(not(target_os = "nto"))]
@@ -170,7 +170,7 @@ impl Condvar {
170170
use crate::sys::time::SystemTime;
171171
use crate::time::Instant;
172172

173-
let mutex = pthread_mutex::raw(mutex);
173+
let mutex = mutex::raw(mutex);
174174
self.verify(mutex);
175175

176176
// OSX implementation of `pthread_cond_timedwait` is buggy

std/src/sys/locks/mutex/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
cfg_if::cfg_if! {
2-
if #[cfg(target_os = "teeos")] {
2+
if #[cfg(any(
3+
target_os = "linux",
4+
target_os = "android",
5+
target_os = "freebsd",
6+
target_os = "openbsd",
7+
target_os = "dragonfly",
8+
all(target_family = "wasm", target_feature = "atomics"),
9+
target_os = "hermit",
10+
))] {
11+
mod futex;
12+
pub use futex::Mutex;
13+
} else if #[cfg(target_os = "fuchsia")] {
14+
mod fuchsia;
15+
pub use fuchsia::Mutex;
16+
} else if #[cfg(any(
17+
target_family = "unix",
18+
target_os = "teeos",
19+
))] {
320
mod pthread;
421
pub use pthread::{Mutex, raw};
522
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {

std/src/sys/locks/rwlock/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
cfg_if::cfg_if! {
2-
if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
2+
if #[cfg(any(
3+
target_os = "linux",
4+
target_os = "android",
5+
target_os = "freebsd",
6+
target_os = "openbsd",
7+
target_os = "dragonfly",
8+
target_os = "fuchsia",
9+
all(target_family = "wasm", target_feature = "atomics"),
10+
target_os = "hermit",
11+
))] {
12+
mod futex;
13+
pub use futex::RwLock;
14+
} else if #[cfg(target_family = "unix")] {
15+
mod queue;
16+
pub use queue::RwLock;
17+
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
318
mod sgx;
419
pub use sgx::RwLock;
520
} else if #[cfg(target_os = "solid_asp3")] {

std/src/sys/pal/hermit/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ pub mod thread_local_dtor;
3939
pub mod thread_local_key;
4040
pub mod time;
4141

42-
#[path = "../unix/locks"]
43-
pub mod locks {
44-
mod futex_condvar;
45-
mod futex_mutex;
46-
mod futex_rwlock;
47-
pub(crate) use futex_condvar::Condvar;
48-
pub(crate) use futex_mutex::Mutex;
49-
pub(crate) use futex_rwlock::RwLock;
50-
}
51-
5242
use crate::io::ErrorKind;
5343
use crate::os::hermit::abi;
5444

std/src/sys/pal/unix/locks/mod.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

std/src/sys/pal/unix/locks/pthread_mutex.rs

Lines changed: 0 additions & 148 deletions
This file was deleted.

std/src/sys/pal/unix/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub mod io;
2020
pub mod kernel_copy;
2121
#[cfg(target_os = "l4re")]
2222
mod l4re;
23-
pub mod locks;
2423
pub mod memchr;
2524
#[cfg(not(target_os = "l4re"))]
2625
pub mod net;

std/src/sys/pal/wasi/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ pub mod time;
4444

4545
cfg_if::cfg_if! {
4646
if #[cfg(target_feature = "atomics")] {
47-
#[path = "../unix/locks"]
48-
pub mod locks {
49-
#![allow(unsafe_op_in_unsafe_fn)]
50-
mod futex_condvar;
51-
mod futex_mutex;
52-
mod futex_rwlock;
53-
pub(crate) use futex_condvar::Condvar;
54-
pub(crate) use futex_mutex::Mutex;
55-
pub(crate) use futex_rwlock::RwLock;
56-
}
5747
} else {
5848
#[path = "../unsupported/locks/mod.rs"]
5949
pub mod locks;

std/src/sys/pal/wasm/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ pub mod time;
4343

4444
cfg_if::cfg_if! {
4545
if #[cfg(target_feature = "atomics")] {
46-
#[path = "../unix/locks"]
47-
pub mod locks {
48-
#![allow(unsafe_op_in_unsafe_fn)]
49-
mod futex_condvar;
50-
mod futex_mutex;
51-
mod futex_rwlock;
52-
pub(crate) use futex_condvar::Condvar;
53-
pub(crate) use futex_mutex::Mutex;
54-
pub(crate) use futex_rwlock::RwLock;
55-
}
5646
#[path = "atomics/futex.rs"]
5747
pub mod futex;
5848
#[path = "atomics/thread.rs"]

0 commit comments

Comments
 (0)