mirror of https://git.musl-libc.org/git/musl
Browse Source
The intent of this is to avoid name space pollution of the C threads implementation. This has two sides to it. First we have to provide symbols that wouldn't pollute the name space for the C threads implementation. Second we have to clean up some internal uses of POSIX functions such that they don't implicitly drag in such symbols.master
committed by
Rich Felker
15 changed files with 76 additions and 29 deletions
@ -1,11 +1,15 @@ |
|||||
#include "pthread_impl.h" |
#include "pthread_impl.h" |
||||
|
|
||||
int pthread_detach(pthread_t t) |
int __pthread_join(pthread_t, void **); |
||||
|
|
||||
|
int __pthread_detach(pthread_t t) |
||||
{ |
{ |
||||
/* Cannot detach a thread that's already exiting */ |
/* Cannot detach a thread that's already exiting */ |
||||
if (a_swap(t->exitlock, 1)) |
if (a_swap(t->exitlock, 1)) |
||||
return pthread_join(t, 0); |
return __pthread_join(t, 0); |
||||
t->detached = 2; |
t->detached = 2; |
||||
__unlock(t->exitlock); |
__unlock(t->exitlock); |
||||
return 0; |
return 0; |
||||
} |
} |
||||
|
|
||||
|
weak_alias(__pthread_detach, pthread_detach); |
||||
|
|||||
@ -1,7 +1,9 @@ |
|||||
#include "pthread_impl.h" |
#include "pthread_impl.h" |
||||
|
|
||||
void *pthread_getspecific(pthread_key_t k) |
static void *__pthread_getspecific(pthread_key_t k) |
||||
{ |
{ |
||||
struct pthread *self = __pthread_self(); |
struct pthread *self = __pthread_self(); |
||||
return self->tsd[k]; |
return self->tsd[k]; |
||||
} |
} |
||||
|
|
||||
|
weak_alias(__pthread_getspecific, pthread_getspecific); |
||||
|
|||||
@ -1,16 +1,20 @@ |
|||||
#include "pthread_impl.h" |
#include "pthread_impl.h" |
||||
#include <sys/mman.h> |
#include <sys/mman.h> |
||||
|
|
||||
|
int __munmap(void *, size_t); |
||||
|
|
||||
static void dummy(void *p) |
static void dummy(void *p) |
||||
{ |
{ |
||||
} |
} |
||||
|
|
||||
int pthread_join(pthread_t t, void **res) |
int __pthread_join(pthread_t t, void **res) |
||||
{ |
{ |
||||
int tmp; |
int tmp; |
||||
pthread_testcancel(); |
pthread_testcancel(); |
||||
while ((tmp = t->tid)) __timedwait(&t->tid, tmp, 0, 0, dummy, 0, 0); |
while ((tmp = t->tid)) __timedwait(&t->tid, tmp, 0, 0, dummy, 0, 0); |
||||
if (res) *res = t->result; |
if (res) *res = t->result; |
||||
if (t->map_base) munmap(t->map_base, t->map_size); |
if (t->map_base) __munmap(t->map_base, t->map_size); |
||||
return 0; |
return 0; |
||||
} |
} |
||||
|
|
||||
|
weak_alias(__pthread_join, pthread_join); |
||||
|
|||||
@ -1,10 +1,14 @@ |
|||||
#include "pthread_impl.h" |
#include "pthread_impl.h" |
||||
|
|
||||
int pthread_mutex_lock(pthread_mutex_t *m) |
int __pthread_mutex_timedlock(pthread_mutex_t *restrict, const struct timespec *restrict); |
||||
|
|
||||
|
int __pthread_mutex_lock(pthread_mutex_t *m) |
||||
{ |
{ |
||||
if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL |
if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL |
||||
&& !a_cas(&m->_m_lock, 0, EBUSY)) |
&& !a_cas(&m->_m_lock, 0, EBUSY)) |
||||
return 0; |
return 0; |
||||
|
|
||||
return pthread_mutex_timedlock(m, 0); |
return __pthread_mutex_timedlock(m, 0); |
||||
} |
} |
||||
|
|
||||
|
weak_alias(__pthread_mutex_lock, pthread_mutex_lock); |
||||
|
|||||
Loading…
Reference in new issue