From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/rustix/src/thread/clock.rs | 96 +++++++++++++++++++++++++++++++++++++++ vendor/rustix/src/thread/futex.rs | 38 ++++++++++++++++ vendor/rustix/src/thread/id.rs | 17 +++++++ vendor/rustix/src/thread/mod.rs | 26 +++++++++++ 4 files changed, 177 insertions(+) create mode 100644 vendor/rustix/src/thread/clock.rs create mode 100644 vendor/rustix/src/thread/futex.rs create mode 100644 vendor/rustix/src/thread/id.rs create mode 100644 vendor/rustix/src/thread/mod.rs (limited to 'vendor/rustix/src/thread') diff --git a/vendor/rustix/src/thread/clock.rs b/vendor/rustix/src/thread/clock.rs new file mode 100644 index 000000000..206703088 --- /dev/null +++ b/vendor/rustix/src/thread/clock.rs @@ -0,0 +1,96 @@ +use crate::{imp, io}; + +pub use imp::time::types::Timespec; + +#[cfg(not(any( + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", // FreeBSD 12 has clock_nanosleep, but libc targets FreeBSD 11. + target_os = "ios", + target_os = "macos", + target_os = "openbsd", + target_os = "redox", + target_os = "wasi", +)))] +pub use imp::time::types::ClockId; + +/// `clock_nanosleep(id, 0, request, remain)`—Sleeps for a duration on a +/// given clock. +/// +/// This is `clock_nanosleep` specialized for the case of a relative sleep +/// interval. See [`clock_nanosleep_absolute`] for absolute intervals. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html +/// [Linux]: https://man7.org/linux/man-pages/man2/clock_nanosleep.2.html +#[cfg(not(any( + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", // FreeBSD 12 has clock_nanosleep, but libc targets FreeBSD 11. + target_os = "ios", + target_os = "macos", + target_os = "openbsd", + target_os = "redox", + target_os = "wasi", +)))] +#[inline] +pub fn clock_nanosleep_relative(id: ClockId, request: &Timespec) -> NanosleepRelativeResult { + imp::thread::syscalls::clock_nanosleep_relative(id, request) +} + +/// `clock_nanosleep(id, TIMER_ABSTIME, request, NULL)`—Sleeps until an +/// absolute time on a given clock. +/// +/// This is `clock_nanosleep` specialized for the case of an absolute sleep +/// interval. See [`clock_nanosleep_relative`] for relative intervals. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html +/// [Linux]: https://man7.org/linux/man-pages/man2/clock_nanosleep.2.html +#[cfg(not(any( + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", // FreeBSD 12 has clock_nanosleep, but libc targets FreeBSD 11. + target_os = "ios", + target_os = "macos", + target_os = "openbsd", + target_os = "redox", + target_os = "wasi", +)))] +#[inline] +pub fn clock_nanosleep_absolute(id: ClockId, request: &Timespec) -> io::Result<()> { + imp::thread::syscalls::clock_nanosleep_absolute(id, request) +} + +/// `nanosleep(request, remain)`—Sleeps for a duration. +/// +/// This effectively uses the system monotonic clock. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html +/// [Linux]: https://man7.org/linux/man-pages/man2/nanosleep.2.html +#[inline] +pub fn nanosleep(request: &Timespec) -> NanosleepRelativeResult { + imp::thread::syscalls::nanosleep(request) +} + +/// A return type for `nanosleep` and `clock_nanosleep_relative`. +#[derive(Debug, Clone)] +#[must_use] +pub enum NanosleepRelativeResult { + /// The sleep completed normally. + Ok, + /// The sleep was interrupted, the remaining time is returned. + Interrupted(Timespec), + /// An invalid time value was provided. + Err(io::Errno), +} diff --git a/vendor/rustix/src/thread/futex.rs b/vendor/rustix/src/thread/futex.rs new file mode 100644 index 000000000..df5b561f1 --- /dev/null +++ b/vendor/rustix/src/thread/futex.rs @@ -0,0 +1,38 @@ +//! Linux `futex`. +//! +//! # Safety +//! +//! Futex is a very low-level mechanism for implementing concurrency +//! primitives. +#![allow(unsafe_code)] + +use crate::thread::Timespec; +use crate::{imp, io}; + +pub use imp::thread::{FutexFlags, FutexOperation}; + +/// `futex(uaddr, op, val, utime, uaddr2, val3)` +/// +/// # References +/// - [Linux `futex` system call] +/// - [Linux `futex` feature] +/// +/// # Safety +/// +/// This is a very low-level feature for implementing synchronization +/// primitives. See the references links above. +/// +/// [Linux `futex` system call]: https://man7.org/linux/man-pages/man2/futex.2.html +/// [Linux `futex` feature]: https://man7.org/linux/man-pages/man7/futex.7.html +#[inline] +pub unsafe fn futex( + uaddr: *mut u32, + op: FutexOperation, + flags: FutexFlags, + val: u32, + utime: *const Timespec, + uaddr2: *mut u32, + val3: u32, +) -> io::Result { + imp::thread::syscalls::futex(uaddr, op, flags, val, utime, uaddr2, val3) +} diff --git a/vendor/rustix/src/thread/id.rs b/vendor/rustix/src/thread/id.rs new file mode 100644 index 000000000..964d2654c --- /dev/null +++ b/vendor/rustix/src/thread/id.rs @@ -0,0 +1,17 @@ +use crate::imp; +use crate::process::Pid; + +/// `gettid()`—Returns the thread ID. +/// +/// This returns the OS thread ID, which is not necessarily the same as the +/// `rust::thread::Thread::id` or the pthread ID. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/gettid.2.html +#[inline] +#[must_use] +pub fn gettid() -> Pid { + imp::thread::syscalls::gettid() +} diff --git a/vendor/rustix/src/thread/mod.rs b/vendor/rustix/src/thread/mod.rs new file mode 100644 index 000000000..ac48b435b --- /dev/null +++ b/vendor/rustix/src/thread/mod.rs @@ -0,0 +1,26 @@ +//! Thread-associated operations. + +#[cfg(not(target_os = "redox"))] +mod clock; +#[cfg(linux_raw)] +mod futex; +#[cfg(any(target_os = "android", target_os = "linux"))] +mod id; + +#[cfg(not(any( + target_os = "dragonfly", + target_os = "emscripten", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "openbsd", + target_os = "redox", + target_os = "wasi", +)))] +pub use clock::{clock_nanosleep_absolute, clock_nanosleep_relative, ClockId}; +#[cfg(not(target_os = "redox"))] +pub use clock::{nanosleep, NanosleepRelativeResult, Timespec}; +#[cfg(linux_raw)] +pub use futex::{futex, FutexFlags, FutexOperation}; +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use id::gettid; -- cgit v1.2.3