1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| | #include "pthread_impl.h"
#include <sys/mman.h>
#include <threads.h>
int __munmap(void *, size_t);
/* We have to be careful to not modify memory at res[1], which we
* might do on 64 bit archs, if we'd just interpret *res (an int) as
* void*. Therefore this can't be a simple tail call to
* __pthread_join.
*
* As additional bonus, C11 threads cannot be canceled, so there is no
* need for a cancelation function pointer, here. */
int thrd_join(thrd_t t, int *res)
{
int tmp;
while ((tmp = t->tid)) __timedwait(&t->tid, tmp, 0, 0, 0, 0, 0);
if (res) *res = (int)(intptr_t)t->result;
if (t->map_base) __munmap(t->map_base, t->map_size);
return thrd_success;
}
|