mirror of
git://git.musl-libc.org/musl
synced 2024-12-17 12:14:42 +00:00
add C11 thread functions operating on tss_t and once_flag
These all have POSIX equivalents, but aside from tss_get, they all have minor changes to the signature or return value and thus need to exist as separate functions.
This commit is contained in:
parent
b7cf71a190
commit
e16f70f452
8
src/thread/call_once.c
Normal file
8
src/thread/call_once.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <threads.h>
|
||||
|
||||
int __pthread_once(once_flag *, void (*)(void));
|
||||
|
||||
void call_once(once_flag *flag, void (*func)(void))
|
||||
{
|
||||
__pthread_once(flag, func);
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#include "pthread_impl.h"
|
||||
#include <threads.h>
|
||||
|
||||
static void *__pthread_getspecific(pthread_key_t k)
|
||||
{
|
||||
@ -7,3 +8,4 @@ static void *__pthread_getspecific(pthread_key_t k)
|
||||
}
|
||||
|
||||
weak_alias(__pthread_getspecific, pthread_getspecific);
|
||||
weak_alias(__pthread_getspecific, tss_get);
|
||||
|
11
src/thread/tss_create.c
Normal file
11
src/thread/tss_create.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include <threads.h>
|
||||
|
||||
int __pthread_key_create(tss_t *, void (*)(void *));
|
||||
|
||||
int tss_create(tss_t *tss, tss_dtor_t dtor)
|
||||
{
|
||||
/* Different error returns are possible. C glues them together into
|
||||
* just failure notification. Can't be optimized to a tail call,
|
||||
* unless thrd_error equals EAGAIN. */
|
||||
return __pthread_key_create(tss, dtor) ? thrd_error : thrd_success;
|
||||
}
|
8
src/thread/tss_delete.c
Normal file
8
src/thread/tss_delete.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <threads.h>
|
||||
|
||||
int __pthread_key_delete(tss_t k);
|
||||
|
||||
void tss_delete(tss_t key)
|
||||
{
|
||||
__pthread_key_delete(key);
|
||||
}
|
13
src/thread/tss_set.c
Normal file
13
src/thread/tss_set.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include "pthread_impl.h"
|
||||
#include <threads.h>
|
||||
|
||||
int tss_set(tss_t k, void *x)
|
||||
{
|
||||
struct pthread *self = __pthread_self();
|
||||
/* Avoid unnecessary COW */
|
||||
if (self->tsd[k] != x) {
|
||||
self->tsd[k] = x;
|
||||
self->tsd_used = 1;
|
||||
}
|
||||
return thrd_success;
|
||||
}
|
Loading…
Reference in New Issue
Block a user