27 lines
620 B
C
27 lines
620 B
C
#ifndef ZINNIA_FUTEX_H
|
|
#define ZINNIA_FUTEX_H
|
|
|
|
#include <zinnia/status.h>
|
|
#include <zinnia/syscall_stubs.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// Blocks the calling thread if *addr == expected.
|
|
// Returns immediately if the value at addr has changed.
|
|
static inline zn_status_t zn_futex_wait(int* addr, int expected) {
|
|
return zn_syscall2(addr, expected, ZN_SYSCALL_FUTEX_WAIT);
|
|
}
|
|
|
|
// Wakes up to `count` threads waiting on the given futex address.
|
|
static inline zn_status_t zn_futex_wake(int* addr, int count) {
|
|
return zn_syscall2(addr, count, ZN_SYSCALL_FUTEX_WAKE);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|