Make improvements

- Improve compatibility with Blink virtual machine
- Add non-POSIX APIs for joining threads and signal masks
- Never ever use anything except 32-bit integers for atomics
- Add some `#undef` statements to workaround `ctags` problems
This commit is contained in:
Justine Tunney 2022-11-10 21:52:47 -08:00
parent b46ac13504
commit f2af97711b
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
114 changed files with 902 additions and 363 deletions

View file

@ -18,6 +18,7 @@
*/
#include "libc/assert.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/strace.internal.h"
#include "libc/thread/thread.h"
#ifdef pthread_spin_lock
@ -44,10 +45,22 @@
*/
errno_t pthread_spin_lock(pthread_spinlock_t *spin) {
int x;
#if defined(SYSDEBUG) && _LOCKTRACE
for (;;) {
x = atomic_exchange_explicit(&spin->_lock, 1, memory_order_acquire);
if (!x) {
LOCKTRACE("pthread_spin_lock(%t)", spin);
break;
}
_unassert(x == 1);
LOCKTRACE("pthread_spin_lock(%t) trying...", spin);
}
#else
for (;;) {
x = atomic_exchange_explicit(&spin->_lock, 1, memory_order_acquire);
if (!x) break;
_unassert(x == 1);
}
#endif
return 0;
}