std: move thread parking to sys::sync
This commit is contained in:
parent
fcc06c894b
commit
a56fd370fc
23 changed files with 25 additions and 57 deletions
|
@ -67,7 +67,7 @@ mod task_queue {
|
||||||
pub mod wait_notify {
|
pub mod wait_notify {
|
||||||
use crate::pin::Pin;
|
use crate::pin::Pin;
|
||||||
use crate::sync::Arc;
|
use crate::sync::Arc;
|
||||||
use crate::sys_common::thread_parking::Parker;
|
use crate::sys::sync::Parker;
|
||||||
|
|
||||||
pub struct Notifier(Arc<Parker>);
|
pub struct Notifier(Arc<Parker>);
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,6 @@ pub mod thread;
|
||||||
pub mod thread_local_dtor;
|
pub mod thread_local_dtor;
|
||||||
#[path = "../unix/thread_local_key.rs"]
|
#[path = "../unix/thread_local_key.rs"]
|
||||||
pub mod thread_local_key;
|
pub mod thread_local_key;
|
||||||
#[path = "../unsupported/thread_parking.rs"]
|
|
||||||
pub mod thread_parking;
|
|
||||||
#[allow(non_upper_case_globals)]
|
#[allow(non_upper_case_globals)]
|
||||||
#[path = "../unix/time.rs"]
|
#[path = "../unix/time.rs"]
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
|
@ -30,8 +30,6 @@ pub mod stdio;
|
||||||
pub mod thread;
|
pub mod thread;
|
||||||
#[path = "../unsupported/thread_local_key.rs"]
|
#[path = "../unsupported/thread_local_key.rs"]
|
||||||
pub mod thread_local_key;
|
pub mod thread_local_key;
|
||||||
#[path = "../unsupported/thread_parking.rs"]
|
|
||||||
pub mod thread_parking;
|
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// Only used on NetBSD. If other platforms start using id-based parking, use
|
||||||
|
// separate modules for each platform.
|
||||||
|
#![cfg(target_os = "netbsd")]
|
||||||
|
|
||||||
use crate::ffi::{c_int, c_void};
|
use crate::ffi::{c_int, c_void};
|
||||||
use crate::ptr;
|
use crate::ptr;
|
||||||
use crate::time::Duration;
|
use crate::time::Duration;
|
|
@ -1,24 +0,0 @@
|
||||||
//! Thread parking on systems without futex support.
|
|
||||||
|
|
||||||
#![cfg(not(any(
|
|
||||||
target_os = "linux",
|
|
||||||
target_os = "android",
|
|
||||||
all(target_os = "emscripten", target_feature = "atomics"),
|
|
||||||
target_os = "freebsd",
|
|
||||||
target_os = "openbsd",
|
|
||||||
target_os = "dragonfly",
|
|
||||||
target_os = "fuchsia",
|
|
||||||
)))]
|
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
|
||||||
if #[cfg(all(target_vendor = "apple", not(miri)))] {
|
|
||||||
mod darwin;
|
|
||||||
pub use darwin::Parker;
|
|
||||||
} else if #[cfg(target_os = "netbsd")] {
|
|
||||||
mod netbsd;
|
|
||||||
pub use netbsd::{current, park, park_timeout, unpark, ThreadId};
|
|
||||||
} else {
|
|
||||||
mod pthread;
|
|
||||||
pub use pthread::Parker;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -14,7 +14,6 @@ pub mod thread;
|
||||||
#[cfg(target_thread_local)]
|
#[cfg(target_thread_local)]
|
||||||
pub mod thread_local_dtor;
|
pub mod thread_local_dtor;
|
||||||
pub mod thread_local_key;
|
pub mod thread_local_key;
|
||||||
pub mod thread_parking;
|
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
|
@ -39,13 +39,6 @@ pub mod thread_local_dtor;
|
||||||
pub mod thread_local_key;
|
pub mod thread_local_key;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
|
||||||
if #[cfg(not(target_feature = "atomics"))] {
|
|
||||||
#[path = "../unsupported/thread_parking.rs"]
|
|
||||||
pub mod thread_parking;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[path = "../unsupported/common.rs"]
|
#[path = "../unsupported/common.rs"]
|
||||||
#[deny(unsafe_op_in_unsafe_fn)]
|
#[deny(unsafe_op_in_unsafe_fn)]
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
|
|
@ -41,15 +41,6 @@ pub mod thread_local_key;
|
||||||
#[path = "../wasi/time.rs"]
|
#[path = "../wasi/time.rs"]
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
|
||||||
if #[cfg(target_feature = "atomics")] {
|
|
||||||
compile_error!("The wasm32-wasip2 target does not support atomics");
|
|
||||||
} else {
|
|
||||||
#[path = "../unsupported/thread_parking.rs"]
|
|
||||||
pub mod thread_parking;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[path = "../unsupported/common.rs"]
|
#[path = "../unsupported/common.rs"]
|
||||||
#[deny(unsafe_op_in_unsafe_fn)]
|
#[deny(unsafe_op_in_unsafe_fn)]
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
|
|
@ -50,8 +50,6 @@ cfg_if::cfg_if! {
|
||||||
} else {
|
} else {
|
||||||
#[path = "../unsupported/thread.rs"]
|
#[path = "../unsupported/thread.rs"]
|
||||||
pub mod thread;
|
pub mod thread;
|
||||||
#[path = "../unsupported/thread_parking.rs"]
|
|
||||||
pub mod thread_parking;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ pub mod stdio;
|
||||||
pub mod thread;
|
pub mod thread;
|
||||||
pub mod thread_local_dtor;
|
pub mod thread_local_dtor;
|
||||||
pub mod thread_local_key;
|
pub mod thread_local_key;
|
||||||
pub mod thread_parking;
|
|
||||||
pub mod time;
|
pub mod time;
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(not(target_vendor = "uwp"))] {
|
if #[cfg(not(target_vendor = "uwp"))] {
|
||||||
|
|
|
@ -18,7 +18,6 @@ pub mod process;
|
||||||
pub mod stdio;
|
pub mod stdio;
|
||||||
pub mod thread;
|
pub mod thread;
|
||||||
pub mod thread_local_key;
|
pub mod thread_local_key;
|
||||||
pub mod thread_parking;
|
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
||||||
#[path = "../unsupported/common.rs"]
|
#[path = "../unsupported/common.rs"]
|
||||||
|
|
|
@ -32,9 +32,6 @@ pub mod time;
|
||||||
#[path = "../unsupported/thread.rs"]
|
#[path = "../unsupported/thread.rs"]
|
||||||
pub mod thread;
|
pub mod thread;
|
||||||
|
|
||||||
#[path = "../unsupported/thread_parking.rs"]
|
|
||||||
pub mod thread_parking;
|
|
||||||
|
|
||||||
mod abi;
|
mod abi;
|
||||||
|
|
||||||
use crate::io as std_io;
|
use crate::io as std_io;
|
||||||
|
|
|
@ -2,8 +2,10 @@ mod condvar;
|
||||||
mod mutex;
|
mod mutex;
|
||||||
mod once;
|
mod once;
|
||||||
mod rwlock;
|
mod rwlock;
|
||||||
|
mod thread_parking;
|
||||||
|
|
||||||
pub use condvar::Condvar;
|
pub use condvar::Condvar;
|
||||||
pub use mutex::Mutex;
|
pub use mutex::Mutex;
|
||||||
pub use once::{Once, OnceState};
|
pub use once::{Once, OnceState};
|
||||||
pub use rwlock::RwLock;
|
pub use rwlock::RwLock;
|
||||||
|
pub use thread_parking::Parker;
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
//! provided by libdispatch, as the underlying Mach semaphore is only dubiously
|
//! provided by libdispatch, as the underlying Mach semaphore is only dubiously
|
||||||
//! public.
|
//! public.
|
||||||
|
|
||||||
|
#![allow(non_camel_case_types)]
|
||||||
|
|
||||||
use crate::pin::Pin;
|
use crate::pin::Pin;
|
||||||
use crate::sync::atomic::{
|
use crate::sync::atomic::{
|
||||||
AtomicI8,
|
AtomicI8,
|
|
@ -18,7 +18,20 @@ cfg_if::cfg_if! {
|
||||||
))] {
|
))] {
|
||||||
mod id;
|
mod id;
|
||||||
pub use id::Parker;
|
pub use id::Parker;
|
||||||
|
} else if #[cfg(target_os = "windows")] {
|
||||||
|
mod windows;
|
||||||
|
pub use windows::Parker;
|
||||||
|
} else if #[cfg(all(target_vendor = "apple", not(miri)))] {
|
||||||
|
mod darwin;
|
||||||
|
pub use darwin::Parker;
|
||||||
|
} else if #[cfg(target_os = "xous")] {
|
||||||
|
mod xous;
|
||||||
|
pub use xous::Parker;
|
||||||
|
} else if #[cfg(target_family = "unix")] {
|
||||||
|
mod pthread;
|
||||||
|
pub use pthread::Parker;
|
||||||
} else {
|
} else {
|
||||||
pub use crate::sys::thread_parking::Parker;
|
mod unsupported;
|
||||||
|
pub use unsupported::Parker;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -134,7 +134,7 @@ impl Parker {
|
||||||
// This implementation doesn't require `unsafe`, but other implementations
|
// This implementation doesn't require `unsafe`, but other implementations
|
||||||
// may assume this is only called by the thread that owns the Parker.
|
// may assume this is only called by the thread that owns the Parker.
|
||||||
//
|
//
|
||||||
// For memory ordering, see std/src/sys_common/thread_parking/futex.rs
|
// For memory ordering, see futex.rs
|
||||||
pub unsafe fn park(self: Pin<&Self>) {
|
pub unsafe fn park(self: Pin<&Self>) {
|
||||||
// If we were previously notified then we consume this notification and
|
// If we were previously notified then we consume this notification and
|
||||||
// return quickly.
|
// return quickly.
|
|
@ -26,7 +26,6 @@ pub mod io;
|
||||||
pub mod lazy_box;
|
pub mod lazy_box;
|
||||||
pub mod process;
|
pub mod process;
|
||||||
pub mod thread_local_dtor;
|
pub mod thread_local_dtor;
|
||||||
pub mod thread_parking;
|
|
||||||
pub mod wstr;
|
pub mod wstr;
|
||||||
pub mod wtf8;
|
pub mod wtf8;
|
||||||
|
|
||||||
|
|
|
@ -174,8 +174,8 @@ use crate::ptr::addr_of_mut;
|
||||||
use crate::str;
|
use crate::str;
|
||||||
use crate::sync::atomic::{AtomicUsize, Ordering};
|
use crate::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use crate::sync::Arc;
|
use crate::sync::Arc;
|
||||||
|
use crate::sys::sync::Parker;
|
||||||
use crate::sys::thread as imp;
|
use crate::sys::thread as imp;
|
||||||
use crate::sys_common::thread_parking::Parker;
|
|
||||||
use crate::sys_common::{AsInner, IntoInner};
|
use crate::sys_common::{AsInner, IntoInner};
|
||||||
use crate::time::{Duration, Instant};
|
use crate::time::{Duration, Instant};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue