2 * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * The C11 threads interface.
37 * This interface is implemented as a light-weight wrapper around
38 * <pthread.h>. To prevent namespace pollution, the once_flag object,
39 * its corresponding ONCE_FLAG_INIT and TSS_DTOR_ITERATIONS have been
40 * copied from this header file. They must be kept in sync.
43 typedef struct pthread_cond *cnd_t;
44 typedef struct pthread_mutex *mtx_t;
45 typedef struct pthread *thrd_t;
53 typedef void (*tss_dtor_t)(void *);
54 typedef int (*thrd_start_t)(void *);
70 #if !defined(__cplusplus) || __cplusplus < 201103L
71 #define thread_local _Thread_local
73 #define ONCE_FLAG_INIT { 0, NULL }
74 #define TSS_DTOR_ITERATIONS 4
77 void call_once(once_flag *, void (*)(void));
78 int cnd_broadcast(cnd_t *);
79 void cnd_destroy(cnd_t *);
80 int cnd_init(cnd_t *);
81 int cnd_signal(cnd_t *);
82 int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict,
83 const struct timespec *__restrict);
84 int cnd_wait(cnd_t *, mtx_t *);
85 void mtx_destroy(mtx_t *);
86 int mtx_init(mtx_t *, int);
87 int mtx_lock(mtx_t *);
88 int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict);
89 int mtx_trylock(mtx_t *);
90 int mtx_unlock(mtx_t *);
91 int thrd_create(thrd_t *, thrd_start_t, void *);
92 thrd_t thrd_current(void);
93 int thrd_detach(thrd_t);
94 int thrd_equal(thrd_t, thrd_t);
97 int thrd_join(thrd_t, int *);
98 int thrd_sleep(const struct timespec *, struct timespec *);
99 void thrd_yield(void);
100 int tss_create(tss_t *, tss_dtor_t);
101 void tss_delete(tss_t);
102 void * tss_get(tss_t);
103 int tss_set(tss_t, void *);
106 #endif /* !_THREADS_H_ */