blob: 86e0164f84da767481a22bf794a6e17fd1c59831 [file] [log] [blame]
Robert Mustacchifc2512c2016-03-28 19:43:25 -07001/*
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.
6 *
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.
10 */
11
12/*
13 * Copyright 2016 Joyent, Inc.
14 */
15
16#ifndef _THREADS_H
17#define _THREADS_H
18
19/*
20 * ISO/IEC C11 threads.h support
21 */
22
23#include <sys/feature_tests.h>
24
25#include <sys/types.h>
26#include <limits.h>
27#include <time.h>
28#include <pthread.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#if !defined(_STRICT_SYMBOLS) || defined(_STDC_C11)
35
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) */
43
44#define thread_local _Thread_local
45#define ONCE_FLAG_INIT PTHREAD_ONCE_INIT
46#define TSS_DTOR_ITERATIONS PTHREAD_DESTRUCTOR_ITERATIONS
47
48typedef pthread_cond_t cnd_t;
49typedef pthread_t thrd_t;
50typedef pthread_key_t tss_t;
51typedef pthread_mutex_t mtx_t;
52typedef void (*tss_dtor_t)(void *);
53typedef int (*thrd_start_t)(void *);
54typedef pthread_once_t once_flag;
55
56enum {
57 mtx_plain = 0x1,
58 mtx_recursive = 0x2,
59 mtx_timed = 0x4
60};
61
62enum {
63 thrd_success = 0,
64 thrd_error = 1,
65 thrd_busy = 2,
66 thrd_timedout = 3,
67 thrd_nomem = 4
68};
69
70extern void call_once(once_flag *, void (*)(void));
71extern int cnd_broadcast(cnd_t *);
72extern void cnd_destroy(cnd_t *);
73extern int cnd_init(cnd_t *);
74extern int cnd_signal(cnd_t *);
75extern int cnd_timedwait(cnd_t *_RESTRICT_KYWD, mtx_t *_RESTRICT_KYWD,
76 const struct timespec *_RESTRICT_KYWD);
77extern int cnd_wait(cnd_t *, mtx_t *);
78extern void mtx_destroy(mtx_t *);
79extern int mtx_init(mtx_t *, int);
80extern int mtx_lock(mtx_t *);
81extern int mtx_timedlock(mtx_t *_RESTRICT_KYWD,
82 const struct timespec *_RESTRICT_KYWD);
83extern int mtx_trylock(mtx_t *);
84extern int mtx_unlock(mtx_t *);
85extern int thrd_create(thrd_t *, thrd_start_t, void *);
86extern thrd_t thrd_current(void);
87extern int thrd_detach(thrd_t);
88extern int thrd_equal(thrd_t, thrd_t);
89extern _NORETURN_KYWD void thrd_exit(int) __NORETURN;
90extern int thrd_join(thrd_t, int *);
91extern int thrd_sleep(const struct timespec *, struct timespec *);
92extern void thrd_yield(void);
93extern int tss_create(tss_t *, tss_dtor_t);
94extern void tss_delete(tss_t);
95extern void *tss_get(tss_t);
96extern int tss_set(tss_t, void *);
97
98#endif /* !_STRICT_SYMBOLS | _STDC_C11 */
99
100#ifdef __cplusplus
101}
102#endif
103
104#endif /* _THREADS_H */