Skip to content

Commit ccb1415

Browse files
committed
Auto merge of rust-lang#121177 - joboet:move_pal_locks, r=ChrisDenton
Move locks to `sys` Part of rust-lang#117276. r? `@ChrisDenton`
2 parents 0243834 + 1b1b6dd commit ccb1415

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+144
-167
lines changed

.reuse/dep5

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Copyright: 2019 The Crossbeam Project Developers
5252
The Rust Project Developers (see https://thanks.rust-lang.org)
5353
License: MIT OR Apache-2.0
5454

55-
Files: library/std/src/sys/pal/unix/locks/fuchsia_mutex.rs
55+
Files: library/std/src/sys/locks/mutex/fuchsia.rs
5656
Copyright: 2016 The Fuchsia Authors
5757
The Rust Project Developers (see https://thanks.rust-lang.org)
5858
License: BSD-2-Clause AND (MIT OR Apache-2.0)

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

+1-1
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 {

library/std/src/sys/pal/itron/condvar.rs library/std/src/sys/locks/condvar/itron.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! POSIX conditional variable implementation based on user-space wait queues.
2-
use super::{abi, error::expect_success_aborting, spin::SpinMutex, task, time::with_tmos_strong};
2+
use crate::sys::pal::itron::{
3+
abi, error::expect_success_aborting, spin::SpinMutex, task, time::with_tmos_strong,
4+
};
35
use crate::{mem::replace, ptr::NonNull, sys::locks::Mutex, time::Duration};
46

57
// The implementation is inspired by the queue-based implementation shown in
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cfg_if::cfg_if! {
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(target_os = "windows")] {
18+
mod windows;
19+
pub use windows::Condvar;
20+
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
21+
mod sgx;
22+
pub use sgx::Condvar;
23+
} else if #[cfg(target_os = "solid_asp3")] {
24+
mod itron;
25+
pub use itron::Condvar;
26+
} else if #[cfg(target_os = "teeos")] {
27+
mod teeos;
28+
pub use teeos::Condvar;
29+
} else if #[cfg(target_os = "xous")] {
30+
mod xous;
31+
pub use xous::Condvar;
32+
} else {
33+
mod no_threads;
34+
pub use no_threads::Condvar;
35+
}
36+
}

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

+4-4
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

library/std/src/sys/pal/sgx/condvar.rs library/std/src/sys/locks/condvar/sgx.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::sys::locks::Mutex;
2+
use crate::sys::pal::waitqueue::{SpinMutex, WaitQueue, WaitVariable};
23
use crate::sys_common::lazy_box::{LazyBox, LazyInit};
34
use crate::time::Duration;
45

5-
use super::waitqueue::{SpinMutex, WaitQueue, WaitVariable};
6-
76
/// FIXME: `UnsafeList` is not movable.
87
struct AllocatedCondvar(SpinMutex<WaitVariable<()>>);
98

library/std/src/sys/pal/windows/locks/condvar.rs library/std/src/sys/locks/condvar/windows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Condvar {
2727
let r = c::SleepConditionVariableSRW(
2828
self.inner.get(),
2929
mutex::raw(mutex),
30-
crate::sys::pal::windows::dur2timeout(dur),
30+
crate::sys::pal::dur2timeout(dur),
3131
0,
3232
);
3333
if r == 0 {

library/std/src/sys/pal/xous/locks/condvar.rs library/std/src/sys/locks/condvar/xous.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use super::mutex::Mutex;
21
use crate::os::xous::ffi::{blocking_scalar, scalar};
32
use crate::os::xous::services::{ticktimer_server, TicktimerScalar};
3+
use crate::sys::locks::Mutex;
44
use crate::time::Duration;
55
use core::sync::atomic::{AtomicUsize, Ordering};
66

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod condvar;
22
mod mutex;
33
mod rwlock;
4+
45
pub use condvar::Condvar;
56
pub use mutex::Mutex;
67
pub use rwlock::RwLock;

library/std/src/sys/pal/itron/mutex.rs library/std/src/sys/locks/mutex/itron.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Mutex implementation backed by μITRON mutexes. Assumes `acre_mtx` and
22
//! `TA_INHERIT` are available.
3-
use super::{
3+
use crate::sys::pal::itron::{
44
abi,
55
error::{expect_success, expect_success_aborting, fail, ItronError},
66
spin::SpinIdOnceCell,
@@ -66,20 +66,3 @@ impl Drop for Mutex {
6666
}
6767
}
6868
}
69-
70-
pub(super) struct MutexGuard<'a>(&'a Mutex);
71-
72-
impl<'a> MutexGuard<'a> {
73-
#[inline]
74-
pub(super) fn lock(x: &'a Mutex) -> Self {
75-
x.lock();
76-
Self(x)
77-
}
78-
}
79-
80-
impl Drop for MutexGuard<'_> {
81-
#[inline]
82-
fn drop(&mut self) {
83-
unsafe { self.0.unlock() };
84-
}
85-
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
cfg_if::cfg_if! {
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+
))] {
20+
mod pthread;
21+
pub use pthread::{Mutex, raw};
22+
} else if #[cfg(target_os = "windows")] {
23+
mod windows;
24+
pub use windows::{Mutex, raw};
25+
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
26+
mod sgx;
27+
pub use sgx::Mutex;
28+
} else if #[cfg(target_os = "solid_asp3")] {
29+
mod itron;
30+
pub use itron::Mutex;
31+
} else if #[cfg(target_os = "xous")] {
32+
mod xous;
33+
pub use xous::Mutex;
34+
} else {
35+
mod no_threads;
36+
pub use no_threads::Mutex;
37+
}
38+
}

library/std/src/sys/pal/sgx/mutex.rs library/std/src/sys/locks/mutex/sgx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::waitqueue::{try_lock_or_false, SpinMutex, WaitQueue, WaitVariable};
1+
use crate::sys::pal::waitqueue::{try_lock_or_false, SpinMutex, WaitQueue, WaitVariable};
22
use crate::sys_common::lazy_box::{LazyBox, LazyInit};
33

44
/// FIXME: `UnsafeList` is not movable.
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cfg_if::cfg_if! {
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(target_os = "windows")] {
18+
mod windows;
19+
pub use windows::RwLock;
20+
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
21+
mod sgx;
22+
pub use sgx::RwLock;
23+
} else if #[cfg(target_os = "solid_asp3")] {
24+
mod solid;
25+
pub use solid::RwLock;
26+
} else if #[cfg(target_os = "teeos")] {
27+
mod teeos;
28+
pub use teeos::RwLock;
29+
} else if #[cfg(target_os = "xous")] {
30+
mod xous;
31+
pub use xous::RwLock;
32+
} else {
33+
mod no_threads;
34+
pub use no_threads::RwLock;
35+
}
36+
}

library/std/src/sys/pal/sgx/rwlock.rs library/std/src/sys/locks/rwlock/sgx.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#[cfg(test)]
22
mod tests;
33

4+
use crate::alloc::Layout;
45
use crate::num::NonZero;
5-
use crate::sys_common::lazy_box::{LazyBox, LazyInit};
6-
7-
use super::waitqueue::{
6+
use crate::sys::pal::waitqueue::{
87
try_lock_or_false, NotifiedTcs, SpinMutex, SpinMutexGuard, WaitQueue, WaitVariable,
98
};
10-
use crate::alloc::Layout;
9+
use crate::sys_common::lazy_box::{LazyBox, LazyInit};
1110

1211
struct AllocatedRwLock {
1312
readers: SpinMutex<WaitVariable<Option<NonZero<usize>>>>,

library/std/src/sys/pal/solid/rwlock.rs library/std/src/sys/locks/rwlock/solid.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! A readers-writer lock implementation backed by the SOLID kernel extension.
2-
use super::{
2+
use crate::sys::pal::{
33
abi,
44
itron::{
55
error::{expect_success, expect_success_aborting, fail, ItronError},

library/std/src/sys/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod pal;
66
mod personality;
77

88
pub mod cmath;
9+
pub mod locks;
910
pub mod os_str;
1011
pub mod path;
1112

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

-10
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

library/std/src/sys/pal/sgx/mod.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use crate::io::ErrorKind;
99
use crate::sync::atomic::{AtomicBool, Ordering};
1010

1111
pub mod abi;
12-
mod waitqueue;
13-
1412
pub mod alloc;
1513
pub mod args;
1614
pub mod env;
@@ -31,16 +29,7 @@ pub mod thread;
3129
pub mod thread_local_key;
3230
pub mod thread_parking;
3331
pub mod time;
34-
35-
mod condvar;
36-
mod mutex;
37-
mod rwlock;
38-
39-
pub mod locks {
40-
pub use super::condvar::*;
41-
pub use super::mutex::*;
42-
pub use super::rwlock::*;
43-
}
32+
pub mod waitqueue;
4433

4534
// SAFETY: must be called only once during runtime initialization.
4635
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.

library/std/src/sys/pal/solid/abi/fs.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! `solid_fs.h`
22
use crate::os::raw::{c_char, c_int, c_uchar};
33
pub use libc::{
4-
blksize_t, dev_t, ino_t, off_t, stat, time_t, O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR,
5-
O_TRUNC, O_WRONLY, SEEK_CUR, SEEK_END, SEEK_SET, S_IEXEC, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO,
6-
S_IFMT, S_IFREG, S_IREAD, S_IWRITE,
4+
ino_t, off_t, stat, time_t, O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY,
5+
SEEK_CUR, SEEK_END, SEEK_SET, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFMT, S_IFREG, S_IWRITE,
76
};
87

98
pub const O_ACCMODE: c_int = 0x3;

library/std/src/sys/pal/solid/abi/sockets.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::os::raw::{c_char, c_uint, c_void};
2-
pub use libc::{c_int, c_long, size_t, ssize_t, suseconds_t, time_t, timeval};
2+
pub use libc::{c_int, c_long, size_t, ssize_t, timeval};
33

44
pub const SOLID_NET_ERR_BASE: c_int = -2000;
55
pub const EINPROGRESS: c_int = SOLID_NET_ERR_BASE - libc::EINPROGRESS;

library/std/src/sys/pal/solid/mod.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
#![allow(missing_docs, nonstandard_style)]
33
#![deny(unsafe_op_in_unsafe_fn)]
44

5-
mod abi;
5+
pub mod abi;
66

77
#[path = "../itron"]
8-
mod itron {
9-
pub(super) mod abi;
10-
pub mod condvar;
11-
pub(super) mod error;
12-
pub mod mutex;
13-
pub(super) mod spin;
14-
pub(super) mod task;
8+
pub mod itron {
9+
pub mod abi;
10+
pub mod error;
11+
pub mod spin;
12+
pub mod task;
1513
pub mod thread;
1614
pub mod thread_parking;
17-
pub(super) mod time;
15+
pub mod time;
1816
use super::unsupported;
1917
}
2018

@@ -41,14 +39,6 @@ pub mod thread_local_key;
4139
pub use self::itron::thread_parking;
4240
pub mod time;
4341

44-
mod rwlock;
45-
46-
pub mod locks {
47-
pub use super::itron::condvar::*;
48-
pub use super::itron::mutex::*;
49-
pub use super::rwlock::*;
50-
}
51-
5242
// SAFETY: must be called only once during runtime initialization.
5343
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
5444
pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {}

library/std/src/sys/pal/teeos/locks/mod.rs

-8
This file was deleted.

library/std/src/sys/pal/teeos/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub mod alloc;
1313
pub mod args;
1414
#[path = "../unsupported/env.rs"]
1515
pub mod env;
16-
pub mod locks;
1716
//pub mod fd;
1817
#[path = "../unsupported/fs.rs"]
1918
pub mod fs;

0 commit comments

Comments
 (0)