| 1 |
#define _GNU_SOURCE |
| 2 |
#include "pthread_impl.h" |
| 3 |
#ifdef __wasilibc_unmodified_upstream |
| 4 |
#include <sys/mman.h> |
| 5 |
#endif |
| 6 |
|
| 7 |
static void dummy1(pthread_t t) |
| 8 |
{ |
| 9 |
} |
| 10 |
weak_alias(dummy1, __tl_sync); |
| 11 |
|
| 12 |
static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at) |
| 13 |
{ |
| 14 |
int state, cs, r = 0; |
| 15 |
__pthread_testcancel(); |
| 16 |
__pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); |
| 17 |
if (cs == PTHREAD_CANCEL_ENABLE) __pthread_setcancelstate(cs, 0); |
| 18 |
while ((state = t->detach_state) && r != ETIMEDOUT && r != EINVAL) { |
| 19 |
if (state >= DT_DETACHED) a_crash(); |
| 20 |
r = __timedwait_cp(&t->detach_state, state, CLOCK_REALTIME, at, 1); |
| 21 |
} |
| 22 |
__pthread_setcancelstate(cs, 0); |
| 23 |
if (r == ETIMEDOUT || r == EINVAL) return r; |
| 24 |
__tl_sync(t); |
| 25 |
if (res) *res = t->result; |
| 26 |
#ifdef __wasilibc_unmodified_upstream |
| 27 |
if (t->map_base) __munmap(t->map_base, t->map_size); |
| 28 |
#else |
| 29 |
if (t->map_base) free(t->map_base); |
| 30 |
#endif |
| 31 |
return 0; |
| 32 |
} |
| 33 |
|
| 34 |
int __pthread_join(pthread_t t, void **res) |
| 35 |
{ |
| 36 |
return __pthread_timedjoin_np(t, res, 0); |
| 37 |
} |
| 38 |
|
| 39 |
static int __pthread_tryjoin_np(pthread_t t, void **res) |
| 40 |
{ |
| 41 |
return t->detach_state==DT_JOINABLE ? EBUSY : __pthread_join(t, res); |
| 42 |
} |
| 43 |
|
| 44 |
weak_alias(__pthread_tryjoin_np, pthread_tryjoin_np); |
| 45 |
weak_alias(__pthread_timedjoin_np, pthread_timedjoin_np); |
| 46 |
weak_alias(__pthread_join, pthread_join); |