1 #define _ALL_SOURCE
2 #include <threads.h>
3
4 #include "threads_impl.h"
5
thrd_create_internal(thrd_t * thr,thrd_start_t func,void * arg,const char * name)6 static int thrd_create_internal(thrd_t* thr, thrd_start_t func, void* arg, const char* name) {
7 pthread_attr_t attrs = DEFAULT_PTHREAD_ATTR;
8 attrs.__name = name;
9 attrs.__c11 = 1;
10 // Technically this could introduce a restrict violation if thr and arg alias.
11 int ret = __pthread_create(thr, &attrs,
12 (void* (*)(void*))(uintptr_t)func, arg);
13 switch (ret) {
14 case 0:
15 return thrd_success;
16 case EAGAIN:
17 return thrd_nomem;
18 default:
19 return thrd_error;
20 }
21 }
22
thrd_create(thrd_t * thr,thrd_start_t func,void * arg)23 int thrd_create(thrd_t* thr, thrd_start_t func, void* arg) {
24 return thrd_create_internal(thr, func, arg, NULL);
25 }
26
27 __typeof(thrd_create_with_name) thrd_create_with_name
28 __attribute__((alias("thrd_create_internal")));
29