Add more POSIX threads APIs

This commit is contained in:
Justine Tunney 2022-09-09 11:30:33 -07:00
parent 1729a8259c
commit c3208eb9d5
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
32 changed files with 592 additions and 87 deletions

View file

@ -18,7 +18,6 @@
*/
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asmflag.h"
#include "libc/intrin/atomic.h"
@ -36,12 +35,10 @@ static int pthread_mutex_lock_spin(pthread_mutex_t *mutex, int expect,
for (i = 0; i != 1 << tries; i++) {
}
tries++;
} else if (IsLinux() || IsOpenbsd()) {
} else {
atomic_fetch_add(&mutex->waits, 1);
_futex_wait(&mutex->lock, expect, mutex->pshared, &(struct timespec){1});
atomic_fetch_sub(&mutex->waits, 1);
} else {
pthread_yield();
}
return tries;
}