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/calls/cp.internal.h"
#include "libc/calls/struct/timespec.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/atomic.h"
@ -37,9 +38,10 @@
*
* @return 0 on success, or errno on error
* @raise ECANCELED if calling thread was cancelled in masked mode
* @raise EBUSY if `abstime` was specified and deadline expired
* @cancellationpoint
*/
errno_t _wait0(const atomic_int *ctid) {
errno_t _wait0(const atomic_int *ctid, struct timespec *abstime) {
int x, rc = 0;
// "The behavior is undefined if the value specified by the thread
// argument to pthread_join() refers to the calling thread."
@ -50,9 +52,13 @@ errno_t _wait0(const atomic_int *ctid) {
if (!(rc = pthread_testcancel_np())) {
BEGIN_CANCELLATION_POINT;
while ((x = atomic_load_explicit(ctid, memory_order_acquire))) {
if (nsync_futex_wait_(ctid, x, !IsWindows(), 0) == -ECANCELED) {
rc = nsync_futex_wait_(ctid, x, !IsWindows(), abstime);
if (rc == -ECANCELED) {
rc = ECANCELED;
break;
} else if (rc == -ETIMEDOUT) {
rc = EBUSY;
break;
}
}
END_CANCELLATION_POINT;