mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +00:00
Implement POSIX threads API
This commit is contained in:
parent
af24f21556
commit
9be364d40a
95 changed files with 6029 additions and 317 deletions
|
@ -20,15 +20,33 @@
|
|||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timespec.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/futex.internal.h"
|
||||
#include "libc/sysv/consts/futex.h"
|
||||
|
||||
int _futex(void *, int, int, struct timespec *) hidden;
|
||||
int _futex_wait(void *addr, int expect, struct timespec *timeout) {
|
||||
int ax = _futex(addr, FUTEX_WAIT, expect, timeout);
|
||||
|
||||
static dontinline int _futex_wait_impl(void *addr, int expect,
|
||||
struct timespec *timeout, int private) {
|
||||
int op, ax;
|
||||
op = FUTEX_WAIT | private;
|
||||
ax = _futex(addr, op, expect, timeout);
|
||||
if (SupportsLinux() && private && ax == -ENOSYS) {
|
||||
// RHEL5 doesn't support FUTEX_PRIVATE_FLAG
|
||||
op = FUTEX_WAIT;
|
||||
ax = _futex(addr, op, expect, timeout);
|
||||
}
|
||||
if (IsOpenbsd() && ax > 0) ax = -ax; // yes openbsd does this w/o cf
|
||||
STRACE("futex(%t, FUTEX_WAIT, %d, %s) → %s", addr, expect,
|
||||
STRACE("futex(%t, %s, %d, %s) → %s", addr, DescribeFutexOp(op), expect,
|
||||
DescribeTimespec(0, timeout), DescribeFutexResult(ax));
|
||||
return ax;
|
||||
}
|
||||
|
||||
int _futex_wait_public(void *addr, int expect, struct timespec *timeout) {
|
||||
return _futex_wait_impl(addr, expect, timeout, 0);
|
||||
}
|
||||
|
||||
int _futex_wait_private(void *addr, int expect, struct timespec *timeout) {
|
||||
return _futex_wait_impl(addr, expect, timeout, FUTEX_PRIVATE_FLAG);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue