initial check-in, version 0.5.0
[musl] / src / thread / pthread_exit.c
1 #include "pthread_impl.h"
2
3 #undef pthread_self
4
5 void pthread_exit(void *result)
6 {
7         int i;
8         struct pthread *self = pthread_self();
9         self->result = result;
10
11         a_dec(&libc.threads_minus_1);
12         if (libc.threads_minus_1 < 0)
13                 exit(0);
14
15         LOCK(&self->exitlock);
16
17         if (self->tsd_used) for (i=0; i<PTHREAD_KEYS_MAX; i++)
18                 if (self->tsd[i] && libc.tsd_keys[i])
19                         libc.tsd_keys[i](self->tsd[i]);
20
21         if (self->detached && self->map_base)
22                 __unmapself(self->map_base, self->map_size);
23
24         __syscall_exit(0);
25 }