22#ifndef LELY_LIBC_THREADS_H_
23#define LELY_LIBC_THREADS_H_
28#ifndef LELY_HAVE_THREADS_H
29#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
30#define LELY_HAVE_THREADS_H 1
35#if LELY_HAVE_THREADS_H
41#ifndef LELY_HAVE_PTHREAD_H
42#if _POSIX_THREADS >= 200112L || defined(__MINGW32__)
43#define LELY_HAVE_PTHREAD_H 1
47#if LELY_HAVE_PTHREAD_H
52#error This file requires POSIX Threads or Windows.
56#if __cplusplus >= 201103L
59#define thread_local _Thread_local
64#if LELY_HAVE_PTHREAD_H
65#define ONCE_FLAG_INIT PTHREAD_ONCE_INIT
67#define ONCE_FLAG_INIT 0
74#define TSS_DTOR_ITERATIONS 1
77#if LELY_HAVE_PTHREAD_H
78typedef pthread_cond_t cnd_t;
80typedef CONDITION_VARIABLE cnd_t;
84#if LELY_HAVE_PTHREAD_H
85typedef pthread_t thrd_t;
94#if LELY_HAVE_PTHREAD_H
95typedef pthread_key_t tss_t;
101#if LELY_HAVE_PTHREAD_H
102typedef pthread_mutex_t mtx_t;
104typedef CRITICAL_SECTION mtx_t;
142#if LELY_HAVE_PTHREAD_H
143typedef pthread_once_t once_flag;
145typedef long once_flag;
156#if LELY_HAVE_PTHREAD_H
157typedef void (*tss_dtor_t)(
void *);
160typedef void (WINAPI *tss_dtor_t)(
void *);
This header file is part of the Lely libraries; it contains the compiler feature definitions.
#define _Noreturn
A function declared with a _Noreturn function specifier SHALL not return to its caller.
This header file is part of the C11 and POSIX compatibility library; it includes <time....
A time type with nanosecond resolution.
This header file is part of the C11 and POSIX compatibility library; it includes <threads....
int cnd_init(cnd_t *cond)
Creates a condition variable.
int(* thrd_start_t)(void *)
A complete object type that holds a flag for use by call_once().
int thrd_equal(thrd_t thr0, thrd_t thr1)
Determines whether the thread identified by thr0 refers to the thread identified by thr1.
int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
Creates a new thread executing func(arg).
int tss_create(tss_t *key, tss_dtor_t dtor)
Creates a thread-specific storage pointer with destructor dtor, which may be NULL.
int cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *ts)
Atomically unlocks the mutex at mtx and endeavors to block until the condition variable at cond is si...
_Noreturn void thrd_exit(int res)
Terminates execution of the calling thread and sets its result code to res.
void * tss_get(tss_t key)
Returns the value for the current thread held in the thread-specific storage identified by key.
int tss_set(tss_t key, void *val)
Sets the value for the current thread held in the thread-specific storage identified by key to val.
int cnd_broadcast(cnd_t *cond)
Unblocks all of the threads that are blocked on the condition variable at cond at the time of the cal...
int thrd_sleep(const struct timespec *duration, struct timespec *remaining)
Suspends execution of the calling thread until either the interval specified by duration has elapsed ...
int mtx_init(mtx_t *mtx, int type)
Creates a mutex object with properties indicated by type, which must have one of the four values:
int mtx_lock(mtx_t *mtx)
Blocks until it locks the mutex at mtx.
int mtx_timedlock(mtx_t *mtx, const struct timespec *ts)
Endeavors to block until it locks the mutex at mtx or until after the TIME_UTC-based calendar time at...
int thrd_join(thrd_t thr, int *res)
Joins the thread identified by thr with the current thread by blocking until the other thread has ter...
void cnd_destroy(cnd_t *cond)
Releases all resources used by the condition variable at cond.
thrd_t thrd_current(void)
Identifies the thread that called it.
void call_once(once_flag *flag, void(*func)(void))
Uses the #once_flag at flag to ensure that func is called exactly once, the first time the call_once(...
int cnd_wait(cnd_t *cond, mtx_t *mtx)
Atomically unlocks the mutex at mtx and endeavors to block until the condition variable at cond is si...
int mtx_trylock(mtx_t *mtx)
Endeavors to lock the mutex at mtx.
void thrd_yield(void)
Endeavors to permit other threads to run, even if the current thread would ordinarily continue to run...
int thrd_detach(thrd_t thr)
Tells the operating system to dispose of any resources allocated to the thread identified by thr when...
@ thrd_timedout
Indicates that the time specified in the call was reached without acquiring the requested resource.
@ thrd_success
Indicates that the requested operation succeeded.
@ thrd_busy
Indicates that the requested operation failed because a resource requested by a test and return funct...
@ thrd_nomem
Indicates that the requested operation failed because it was unable to allocate memory.
@ thrd_error
Indicates that the requested operation failed.
int mtx_unlock(mtx_t *mtx)
Unlocks the mutex at mtx.
void mtx_destroy(mtx_t *mtx)
Releases any resources used by the mutex at mtx.
void tss_delete(tss_t key)
Releases any resources used by the thread-specific storage identified by key.
int cnd_signal(cnd_t *cond)
Unblocks one of the threads that are blocked on the condition variable at cond at the time of the cal...
@ mtx_timed
A mutex type that supports timeout (not available with the native Windows API).
@ mtx_plain
A mutex type that supports neither timeout nor test and return.
@ mtx_recursive
A mutex type that supports recursive locking.