Implement POSIX threads API

This commit is contained in:
Justine Tunney 2022-09-05 08:26:03 -07:00
parent af24f21556
commit 9be364d40a
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
95 changed files with 6029 additions and 317 deletions

View file

@ -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);
}