mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
std: connect sys::sync::futex and drop the pal declarations
Select the platform implementation with a cfg_select! in sys::sync::futex, repoint each one at the pal primitives it uses (time, fuchsia, the windows api module, hermit_abi), and remove the now-unused futex declarations from the pal modules. The sync primitives import crate::sys::sync::futex rather than the crate::sys::futex glob re-export.
This commit is contained in:
@@ -33,3 +33,6 @@ c682aa162b0d41e21cc6748f4fecfe01efb69d1f
|
||||
1fcae03369abb4c2cc180cd5a49e1f4440a81300
|
||||
# Breaking up of compiletest runtest.rs
|
||||
60600a6fa403216bfd66e04f948b1822f6450af7
|
||||
|
||||
# std: move futex implementations into sys::sync::futex
|
||||
7232830d10b6af772e0e4670a2ff61dd23830ed8
|
||||
|
||||
@@ -21,7 +21,6 @@ use crate::os::hermit::hermit_abi;
|
||||
use crate::os::raw::c_char;
|
||||
use crate::sys::env;
|
||||
|
||||
pub mod futex;
|
||||
#[path = "../unix/time.rs"]
|
||||
pub mod time;
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#![allow(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
pub use moto_rt::futex;
|
||||
|
||||
use crate::io;
|
||||
|
||||
pub(crate) fn map_motor_error(err: moto_rt::Error) -> io::Error {
|
||||
|
||||
@@ -5,7 +5,6 @@ use crate::io;
|
||||
pub mod conf;
|
||||
#[cfg(target_os = "fuchsia")]
|
||||
pub mod fuchsia;
|
||||
pub mod futex;
|
||||
pub mod stack_overflow;
|
||||
pub mod sync;
|
||||
pub mod thread_parking;
|
||||
|
||||
@@ -11,24 +11,6 @@ pub mod stack_overflow;
|
||||
#[path = "../unix/time.rs"]
|
||||
pub mod time;
|
||||
|
||||
// The wasi-libc based futex is new enough that it's not present in older
|
||||
// wasi-libc builds. For now that means it's only required on wasip3 (which
|
||||
// requires a newer wasi-libc anyway). In the future this'll probably switch to
|
||||
// unconditionally using `wasilibc_futex` as the implementation for all WASI
|
||||
// targets (and switching all synchronization primitives to the futex version).
|
||||
cfg_select! {
|
||||
target_env = "p3" => {
|
||||
pub mod wasilibc_futex;
|
||||
pub use wasilibc_futex as futex;
|
||||
}
|
||||
target_feature = "atomics" => {
|
||||
#[allow(unused)]
|
||||
#[path = "../wasm/atomics/futex.rs"]
|
||||
pub mod futex;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
#[cfg(not(target_env = "p1"))]
|
||||
mod cabi_realloc;
|
||||
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
#[cfg(target_feature = "atomics")]
|
||||
#[path = "atomics/futex.rs"]
|
||||
pub mod futex;
|
||||
|
||||
#[path = "../unsupported/common.rs"]
|
||||
#[deny(unsafe_op_in_unsafe_fn)]
|
||||
mod common;
|
||||
|
||||
@@ -15,8 +15,6 @@ pub mod compat;
|
||||
pub mod api;
|
||||
|
||||
pub mod c;
|
||||
#[cfg(not(target_vendor = "win7"))]
|
||||
pub mod futex;
|
||||
pub mod handle;
|
||||
pub mod time;
|
||||
cfg_select! {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::sync::atomic::Ordering::Relaxed;
|
||||
use crate::sys::futex::{Futex, futex_wait, futex_wake, futex_wake_all};
|
||||
use crate::sys::sync::Mutex;
|
||||
use crate::sys::sync::futex::{Futex, futex_wait, futex_wake, futex_wake_all};
|
||||
use crate::time::Duration;
|
||||
|
||||
pub struct Condvar {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::hermit_abi;
|
||||
use crate::os::hermit::hermit_abi;
|
||||
use crate::ptr::null;
|
||||
use crate::sync::atomic::Atomic;
|
||||
use crate::time::Duration;
|
||||
|
||||
39
library/std/src/sys/sync/futex/mod.rs
Normal file
39
library/std/src/sys/sync/futex/mod.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
cfg_select! {
|
||||
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",
|
||||
) => {
|
||||
mod unix;
|
||||
pub use unix::*;
|
||||
}
|
||||
all(target_os = "windows", not(target_vendor = "win7")) => {
|
||||
mod windows;
|
||||
pub use windows::*;
|
||||
}
|
||||
target_os = "hermit" => {
|
||||
mod hermit;
|
||||
pub use hermit::*;
|
||||
}
|
||||
// The wasi-libc based futex is new enough that it's not present in older
|
||||
// wasi-libc builds. For now that means it's only required on wasip3 (which
|
||||
// requires a newer wasi-libc anyway). In the future this'll probably switch to
|
||||
// unconditionally using `wasilibc` as the implementation for all WASI
|
||||
// targets (and switching all synchronization primitives to the futex version).
|
||||
all(target_os = "wasi", target_env = "p3") => {
|
||||
mod wasilibc;
|
||||
pub use wasilibc::*;
|
||||
}
|
||||
all(target_family = "wasm", target_feature = "atomics") => {
|
||||
mod wasm;
|
||||
pub use wasm::*;
|
||||
}
|
||||
target_os = "motor" => {
|
||||
pub use moto_rt::futex::*;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -1,13 +1,3 @@
|
||||
#![cfg(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",
|
||||
))]
|
||||
|
||||
use crate::sync::atomic::Atomic;
|
||||
use crate::time::Duration;
|
||||
|
||||
@@ -28,9 +18,9 @@ pub type SmallPrimitive = u32;
|
||||
/// Returns false on timeout, and true in all other cases.
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
|
||||
pub fn futex_wait(futex: &Atomic<u32>, expected: u32, timeout: Option<Duration>) -> bool {
|
||||
use super::time::Timespec;
|
||||
use crate::ptr::null;
|
||||
use crate::sync::atomic::Ordering::Relaxed;
|
||||
use crate::sys::pal::time::Timespec;
|
||||
|
||||
// Calculate the timeout as an absolute timespec.
|
||||
//
|
||||
@@ -149,8 +139,8 @@ pub fn futex_wake_all(futex: &Atomic<u32>) {
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
pub fn futex_wait(futex: &Atomic<u32>, expected: u32, timeout: Option<Duration>) -> bool {
|
||||
use super::time::Timespec;
|
||||
use crate::ptr::{null, null_mut};
|
||||
use crate::sys::pal::time::Timespec;
|
||||
|
||||
// Overflows are rounded up to an infinite timeout (None).
|
||||
let timespec = timeout
|
||||
@@ -258,7 +248,7 @@ pub fn futex_wake_all(futex: &Atomic<u32>) {
|
||||
|
||||
#[cfg(target_os = "fuchsia")]
|
||||
pub fn futex_wait(futex: &Atomic<u32>, expected: u32, timeout: Option<Duration>) -> bool {
|
||||
use super::fuchsia::*;
|
||||
use crate::sys::pal::fuchsia::*;
|
||||
|
||||
// Sleep forever if the timeout is longer than fits in a i64.
|
||||
let deadline = timeout
|
||||
@@ -274,11 +264,11 @@ pub fn futex_wait(futex: &Atomic<u32>, expected: u32, timeout: Option<Duration>)
|
||||
// Fuchsia doesn't tell us how many threads are woken up, so this always returns false.
|
||||
#[cfg(target_os = "fuchsia")]
|
||||
pub fn futex_wake(futex: &Atomic<u32>) -> bool {
|
||||
unsafe { super::fuchsia::zx_futex_wake(futex, 1) };
|
||||
unsafe { crate::sys::pal::fuchsia::zx_futex_wake(futex, 1) };
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(target_os = "fuchsia")]
|
||||
pub fn futex_wake_all(futex: &Atomic<u32>) {
|
||||
unsafe { super::fuchsia::zx_futex_wake(futex, u32::MAX) };
|
||||
unsafe { crate::sys::pal::fuchsia::zx_futex_wake(futex, u32::MAX) };
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use core::sync::atomic::{
|
||||
};
|
||||
use core::time::Duration;
|
||||
|
||||
use super::api::{self, WinError};
|
||||
use crate::sys::pal::api::{self, WinError};
|
||||
use crate::sys::{c, dur2timeout};
|
||||
|
||||
/// An atomic for use as a futex that is at least 32-bits but may be larger
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
mod condvar;
|
||||
mod futex;
|
||||
mod mutex;
|
||||
mod once;
|
||||
mod once_box;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
|
||||
use crate::sys::futex::{self, futex_wait, futex_wake};
|
||||
use crate::sys::sync::futex::{self, futex_wait, futex_wake};
|
||||
|
||||
type Futex = futex::SmallFutex;
|
||||
type State = futex::SmallPrimitive;
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::cell::Cell;
|
||||
use crate::sync as public;
|
||||
use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
|
||||
use crate::sync::once::OnceExclusiveState;
|
||||
use crate::sys::futex::{Futex, Primitive, futex_wait, futex_wake_all};
|
||||
use crate::sys::sync::futex::{Futex, Primitive, futex_wait, futex_wake_all};
|
||||
|
||||
// On some platforms, the OS is very nice and handles the waiter queue for us.
|
||||
// This means we only need one atomic value with 4 states:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
|
||||
use crate::sys::futex::{Futex, Primitive, futex_wait, futex_wake, futex_wake_all};
|
||||
use crate::sys::sync::futex::{Futex, Primitive, futex_wait, futex_wake, futex_wake_all};
|
||||
|
||||
pub struct RwLock {
|
||||
// The state consists of a 30-bit reader counter, a 'readers waiting' flag, and a 'writers waiting' flag.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||
use crate::pin::Pin;
|
||||
use crate::sync::atomic::Ordering::{Acquire, Release};
|
||||
use crate::sys::futex::{self, futex_wait, futex_wake};
|
||||
use crate::sys::sync::futex::{self, futex_wait, futex_wake};
|
||||
use crate::time::Duration;
|
||||
|
||||
type Futex = futex::SmallFutex;
|
||||
|
||||
Reference in New Issue
Block a user