Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ c682aa162b0d41e21cc6748f4fecfe01efb69d1f
1fcae03369abb4c2cc180cd5a49e1f4440a81300
# Breaking up of compiletest runtest.rs
60600a6fa403216bfd66e04f948b1822f6450af7

# std: move futex implementations into sys::sync::futex
7232830d10b6af772e0e4670a2ff61dd23830ed8
1 change: 0 additions & 1 deletion library/std/src/sys/pal/hermit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/motor/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 0 additions & 18 deletions library/std/src/sys/pal/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/sync/condvar/futex.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
39 changes: 39 additions & 0 deletions library/std/src/sys/sync/futex/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
}
_ => {}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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.
//
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) };
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/sync/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod condvar;
mod futex;
mod mutex;
mod once;
mod once_box;
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/sync/mutex/futex.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/sync/once/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/sync/rwlock/futex.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/sync/thread_parking/futex.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading