-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move linux-specific futex code into
sys
module.
- Loading branch information
Showing
4 changed files
with
42 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#![cfg(any(target_os = "linux", target_os = "android"))] | ||
|
||
use crate::sync::atomic::AtomicI32; | ||
use crate::time::Duration; | ||
|
||
pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) { | ||
let timespec; | ||
let timespec_ptr = match timeout { | ||
Some(timeout) => { | ||
timespec = libc::timespec { | ||
tv_sec: timeout.as_secs() as _, | ||
tv_nsec: timeout.subsec_nanos() as _, | ||
}; | ||
×pec as *const libc::timespec | ||
} | ||
None => crate::ptr::null(), | ||
}; | ||
unsafe { | ||
libc::syscall( | ||
libc::SYS_futex, | ||
futex as *const AtomicI32, | ||
libc::FUTEX_WAIT | libc::FUTEX_PRIVATE_FLAG, | ||
expected, | ||
timespec_ptr, | ||
); | ||
} | ||
} | ||
|
||
pub fn futex_wake(futex: &AtomicI32) { | ||
unsafe { | ||
libc::syscall( | ||
libc::SYS_futex, | ||
futex as *const AtomicI32, | ||
libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG, | ||
1, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters