-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for FUTEX_{WAIT,WAKE}_BITSET #2054
Changes from 2 commits
37cefa3
a72a929
12c8888
53ed500
5581e33
03417de
4fdda31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#![feature(rustc_private)] | ||
extern crate libc; | ||
|
||
use std::mem::MaybeUninit; | ||
use std::ptr; | ||
use std::thread; | ||
use std::time::{Duration, Instant}; | ||
|
@@ -93,6 +94,42 @@ fn wait_timeout() { | |
assert!((200..1000).contains(&start.elapsed().as_millis())); | ||
} | ||
|
||
fn wait_absolute_timeout() { | ||
let start = Instant::now(); | ||
|
||
// Get the current monotonic timestamp as timespec. | ||
let mut timeout = unsafe { | ||
let mut now: MaybeUninit<libc::timespec> = MaybeUninit::uninit(); | ||
assert_eq!(libc::clock_gettime(libc::CLOCK_MONOTONIC, now.as_mut_ptr()), 0); | ||
now.assume_init() | ||
}; | ||
|
||
// Add 200ms. | ||
timeout.tv_nsec += 200_000_000; | ||
if timeout.tv_nsec > 1_000_000_000 { | ||
timeout.tv_nsec -= 1_000_000_000; | ||
timeout.tv_sec += 1; | ||
} | ||
|
||
let futex: i32 = 123; | ||
|
||
// Wait for 200ms from now, with nobody waking us up early. | ||
unsafe { | ||
assert_eq!(libc::syscall( | ||
libc::SYS_futex, | ||
&futex as *const i32, | ||
libc::FUTEX_WAIT_BITSET, | ||
123, | ||
&timeout, | ||
0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This turns out to be a subtle bug, since (It'd probably still work on x86 due to details of the calling convention, but e.g. if arguments are passed on the stack then |
||
u32::MAX, | ||
), -1); | ||
assert_eq!(*libc::__errno_location(), libc::ETIMEDOUT); | ||
} | ||
|
||
assert!((200..1000).contains(&start.elapsed().as_millis())); | ||
} | ||
|
||
fn wait_wake() { | ||
let start = Instant::now(); | ||
|
||
|
@@ -128,5 +165,6 @@ fn main() { | |
wake_dangling(); | ||
wait_wrong_val(); | ||
wait_timeout(); | ||
wait_absolute_timeout(); | ||
wait_wake(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test also passes if I put FUTEX_WAIT here, as it seems that the monotonic clock starts at zero in the tests. It'd be a better test if it was run with a monotonic clock that does not start at zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, our monotone clock is relative to the
time_anchor
which is initialized viaInstant::now()
when the interpreter starts.I guess we could add an arbitrary offset to that? It also should make a difference if the interpreter has already been running for a bit (e.g. because of a previous timeout test).