dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / include / threads.h
blob86e0164f84da767481a22bf794a6e17fd1c59831
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2016 Joyent, Inc.
16 #ifndef _THREADS_H
17 #define _THREADS_H
20 * ISO/IEC C11 threads.h support
23 #include <sys/feature_tests.h>
25 #include <sys/types.h>
26 #include <limits.h>
27 #include <time.h>
28 #include <pthread.h>
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
34 #if !defined(_STRICT_SYMBOLS) || defined(_STDC_C11)
36 #if !defined(_NORETURN_KYWD)
37 #if __STDC_VERSION__ - 0 >= 201112L
38 #define _NORETURN_KYWD _Noreturn
39 #else
40 #define _NORETURN_KYWD
41 #endif /* __STDC_VERSION__ - 0 >= 201112L */
42 #endif /* !defined(_NORETURN_KYWD) */
44 #define thread_local _Thread_local
45 #define ONCE_FLAG_INIT PTHREAD_ONCE_INIT
46 #define TSS_DTOR_ITERATIONS PTHREAD_DESTRUCTOR_ITERATIONS
48 typedef pthread_cond_t cnd_t;
49 typedef pthread_t thrd_t;
50 typedef pthread_key_t tss_t;
51 typedef pthread_mutex_t mtx_t;
52 typedef void (*tss_dtor_t)(void *);
53 typedef int (*thrd_start_t)(void *);
54 typedef pthread_once_t once_flag;
56 enum {
57 mtx_plain = 0x1,
58 mtx_recursive = 0x2,
59 mtx_timed = 0x4
62 enum {
63 thrd_success = 0,
64 thrd_error = 1,
65 thrd_busy = 2,
66 thrd_timedout = 3,
67 thrd_nomem = 4
70 extern void call_once(once_flag *, void (*)(void));
71 extern int cnd_broadcast(cnd_t *);
72 extern void cnd_destroy(cnd_t *);
73 extern int cnd_init(cnd_t *);
74 extern int cnd_signal(cnd_t *);
75 extern int cnd_timedwait(cnd_t *_RESTRICT_KYWD, mtx_t *_RESTRICT_KYWD,
76 const struct timespec *_RESTRICT_KYWD);
77 extern int cnd_wait(cnd_t *, mtx_t *);
78 extern void mtx_destroy(mtx_t *);
79 extern int mtx_init(mtx_t *, int);
80 extern int mtx_lock(mtx_t *);
81 extern int mtx_timedlock(mtx_t *_RESTRICT_KYWD,
82 const struct timespec *_RESTRICT_KYWD);
83 extern int mtx_trylock(mtx_t *);
84 extern int mtx_unlock(mtx_t *);
85 extern int thrd_create(thrd_t *, thrd_start_t, void *);
86 extern thrd_t thrd_current(void);
87 extern int thrd_detach(thrd_t);
88 extern int thrd_equal(thrd_t, thrd_t);
89 extern _NORETURN_KYWD void thrd_exit(int) __NORETURN;
90 extern int thrd_join(thrd_t, int *);
91 extern int thrd_sleep(const struct timespec *, struct timespec *);
92 extern void thrd_yield(void);
93 extern int tss_create(tss_t *, tss_dtor_t);
94 extern void tss_delete(tss_t);
95 extern void *tss_get(tss_t);
96 extern int tss_set(tss_t, void *);
98 #endif /* !_STRICT_SYMBOLS | _STDC_C11 */
100 #ifdef __cplusplus
102 #endif
104 #endif /* _THREADS_H */