|
ginnOS
The reference: libc, the libraries and the kernel
|
futex wait and wake (futex.h), and SYS_futex. More...
#include "futex.h"#include "kernel/process/process.h"#include "kernel/scheduler/scheduler.h"#include "kernel/signal/signal.h"#include "kernel/syscall/syscall_internal.h"#include "kernel/time/clock.h"#include "kernel/time/timer.h"#include "arch/arch.h"Macros | |
| #define | FUTEX_WAIT 0 |
| #define | FUTEX_WAKE 1 |
| #define | FUTEX_PRIVATE_FLAG 128 |
| #define | FUTEX_QUEUES 16 |
Functions | |
| void | futex_init (void) |
| set up the queues. | |
| int | futex_wake (struct user_space *space, uintptr_t uaddr, int count) |
| wake threads that sleep on a futex. | |
| syscall_ret_t | sys_futex (struct registers *regs) |
| SYS_futex: args: uaddr (an aligned 32-bit word), op, val, timeout. | |
futex wait and wake (futex.h), and SYS_futex.
the waiters sleep on one of a few timed queues, chosen by the futex address. a wake takes the waiters of its futex off the queue and leaves the others. a waiter with a timeout also wakes when the queue's deadline comes (with the others on that queue, which sleep again).
each queue has a lock (a hash bucket, as in Linux). a waiter holds it from the check of the word until it is asleep; a waker changes the word first, then takes the lock, so a wake between the check and the sleep cannot be lost.
| #define FUTEX_WAIT 0 |
| #define FUTEX_WAKE 1 |
| #define FUTEX_PRIVATE_FLAG 128 |
| #define FUTEX_QUEUES 16 |
| void futex_init | ( | void | ) |
set up the queues.
call once at boot, before the first futex call.
| int futex_wake | ( | struct user_space * | space, |
| uintptr_t | uaddr, | ||
| int | count ) |
wake threads that sleep on a futex.
| space | the address space of the futex. |
| uaddr | its user address. |
| count | the most threads to wake. |
| syscall_ret_t sys_futex | ( | struct registers * | regs | ) |
SYS_futex: args: uaddr (an aligned 32-bit word), op, val, timeout.
FUTEX_WAIT sleeps while *uaddr == val, for at most *timeout (a relative struct timespec; NULL: no limit). FUTEX_WAKE wakes at most val threads and returns how many it woke. FUTEX_PRIVATE_FLAG may be set: every futex is private to its process here. returns as above, -EINVAL (a bad address or time), -ENOSYS (another op).