Introduce cosmo_futex_wait and cosmo_futex_wake

Cosmopolitan Futexes are now exposed as a public API.
This commit is contained in:
Justine Tunney 2024-11-22 11:08:29 -08:00
parent 729f7045e3
commit 9ddbfd921e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
66 changed files with 886 additions and 917 deletions

View file

@ -21,7 +21,9 @@
#include "libc/thread/thread.h"
#include "third_party/nsync/atomic.h"
#include "third_party/nsync/atomic.internal.h"
#include "third_party/nsync/futex.internal.h"
#include "libc/cosmo.h"
#include "libc/calls/struct/timespec.h"
#include "libc/cosmo.h"
#include "third_party/nsync/mu_semaphore.internal.h"
/**
@ -61,7 +63,7 @@ errno_t nsync_mu_semaphore_p_futex (nsync_semaphore *s) {
i = ATM_LOAD ((nsync_atomic_uint32_ *) &f->i);
if (i == 0) {
int futex_result;
futex_result = -nsync_futex_wait_ (
futex_result = -cosmo_futex_wait (
(atomic_int *)&f->i, i,
PTHREAD_PROCESS_PRIVATE, 0, 0);
ASSERT (futex_result == 0 ||
@ -100,9 +102,9 @@ errno_t nsync_mu_semaphore_p_with_deadline_futex (nsync_semaphore *s, int clock,
ts_buf.tv_nsec = NSYNC_TIME_NSEC (abs_deadline);
ts = &ts_buf;
}
futex_result = nsync_futex_wait_ ((atomic_int *)&f->i, i,
PTHREAD_PROCESS_PRIVATE,
clock, ts);
futex_result = cosmo_futex_wait ((atomic_int *)&f->i, i,
PTHREAD_PROCESS_PRIVATE,
clock, ts);
ASSERT (futex_result == 0 ||
futex_result == -EINTR ||
futex_result == -EAGAIN ||
@ -136,5 +138,5 @@ void nsync_mu_semaphore_v_futex (nsync_semaphore *s) {
(nsync_atomic_uint32_ *) &f->i, &old_value, old_value+1,
memory_order_release, memory_order_relaxed)) {
}
ASSERT (nsync_futex_wake_ ((atomic_int *)&f->i, 1, PTHREAD_PROCESS_PRIVATE) >= 0);
ASSERT (cosmo_futex_wake ((atomic_int *)&f->i, 1, PTHREAD_PROCESS_PRIVATE) >= 0);
}