libroot: Add support for C11 Threads missing parts (except gcc2).

The respective files can be found in the FreeBSD source tree at:
- lib/libstdthreads/call_once.c
- lib/libstdthreads/cnd.c
- lib/libstdthreads/mtx.c
- lib/libstdthreads/threads.h
- lib/libstdthreads/tss.c

Missing is support for PTHREAD_DESTRUCTOR_ITERATIONS.

Change-Id: I7a6c79954f36195eadd1351d308c21a001192232
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5675
Reviewed-by: Fredrik Holmqvist <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Jérôme Duval
2022-09-19 19:45:45 +00:00
parent 4125af2aeb
commit 799ab823bb
7 changed files with 367 additions and 1 deletions
+3
View File
@@ -49,6 +49,9 @@
#define PTHREAD_PRIO_INHERIT 1
#define PTHREAD_PRIO_PROTECT 2
#define PTHREAD_DESTRUCTOR_ITERATIONS 4
/* private structure */
struct __pthread_cleanup_handler {
struct __pthread_cleanup_handler *previous;
+38
View File
@@ -37,9 +37,21 @@
#include <sys/types.h>
#include <time.h>
typedef pthread_cond_t cnd_t;
typedef pthread_mutex_t mtx_t;
typedef pthread_t thrd_t;
typedef pthread_key_t tss_t;
typedef pthread_once_t once_flag;
typedef void (*tss_dtor_t)(void *);
typedef int (*thrd_start_t)(void *);
enum {
mtx_plain = 0x1,
mtx_recursive = 0x2,
mtx_timed = 0x4
};
enum {
thrd_busy = 1,
thrd_error = 2,
@@ -48,10 +60,31 @@ enum {
thrd_timedout = 5
};
#if !defined(__cplusplus) || __cplusplus < 201103L
#define thread_local _Thread_local
#endif
#define ONCE_FLAG_INIT { 0 }
#define TSS_DTOR_ITERATIONS 4
#ifdef __cplusplus
extern "C" {
#endif
void call_once(once_flag *, void (*)(void));
int cnd_broadcast(cnd_t *);
void cnd_destroy(cnd_t *);
int cnd_init(cnd_t *);
int cnd_signal(cnd_t *);
int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict __mtx,
const struct timespec *__restrict);
int cnd_wait(cnd_t *, mtx_t *__mtx);
void mtx_destroy(mtx_t *__mtx);
int mtx_init(mtx_t *__mtx, int);
int mtx_lock(mtx_t *__mtx);
int mtx_timedlock(mtx_t *__restrict __mtx,
const struct timespec *__restrict);
int mtx_trylock(mtx_t *__mtx);
int mtx_unlock(mtx_t *__mtx);
int thrd_create(thrd_t *thread, thrd_start_t, void *);
thrd_t thrd_current(void);
int thrd_detach(thrd_t);
@@ -62,6 +95,11 @@ int thrd_join(thrd_t, int *);
int thrd_sleep(const struct timespec *, struct timespec *);
void thrd_yield(void);
int tss_create(tss_t *, tss_dtor_t);
void tss_delete(tss_t);
void * tss_get(tss_t);
int tss_set(tss_t, void *);
#ifdef __cplusplus
}
#endif