Add much of C11 threads.h API

This commit is contained in:
Justine Tunney 2024-04-28 07:03:56 -07:00
parent 2bfd6b37c1
commit 0eef971494
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 141 additions and 0 deletions

36
libc/thread/threads.h Normal file
View file

@ -0,0 +1,36 @@
#ifndef COSMOPOLITAN_LIBC_THREAD_THREADS_H_
#define COSMOPOLITAN_LIBC_THREAD_THREADS_H_
COSMOPOLITAN_C_START_
#define TSS_DTOR_ITERATIONS 4
enum {
thrd_success = 0,
thrd_busy = 1,
thrd_error = 2,
thrd_nomem = 3,
thrd_timedout = 4,
};
enum {
mtx_plain = 0,
mtx_recursive = 1,
mtx_timed = 2,
};
typedef uintptr_t thrd_t;
typedef void (*tss_dtor_t)(void *);
typedef int (*thrd_start_t)(void *);
typedef _Atomic(uint32_t) once_flag;
void call_once(once_flag *, void (*)(void));
int thrd_create(thrd_t *, thrd_start_t, void *);
void thrd_exit(int) wontreturn;
int thrd_join(thrd_t, int *);
int thrd_detach(thrd_t);
int thrd_equal(thrd_t, thrd_t);
thrd_t thrd_current(void);
void thrd_yield(void);
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_THREAD_THREADS_H_ */