KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
_threads.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 machine/_threads.h
4 Copyright (C) 2014 Lawrence Sebald
5*/
6
7/** \file machine/_threads.h
8 \brief C11 Threading API.
9 \ingroup threading_c11
10
11 This file contains the platform-specific definitions needed for using
12 C11 threads. The C11 standard defines a number of threading-related
13 primitives, which we wrap neatly around KOS' built-in threading support here.
14
15 If you compile your code with a strict standard set (you use a -std= flag
16 with GCC that doesn't start with gnu), you must use -std=c11 to use this
17 functionality. If you don't pass a -std= flag to GCC, then you're probably
18 fine.
19
20 \author Lawrence Sebald
21*/
22
23#ifndef __MACHINE_THREADS_H
24#define __MACHINE_THREADS_H
25
26#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 201112L)
27
28#include <sys/cdefs.h>
29#include <time.h>
30
31/* Bring in all the threading-related stuff we'll need. */
32#include <kos/thread.h>
33#include <kos/once.h>
34#include <kos/mutex.h>
35#include <kos/cond.h>
36#include <kos/tls.h>
37
38__BEGIN_DECLS
39
40/** \defgroup threading_c11 C11
41 \brief C11 Threading APIs
42 \ingroup threading
43
44 @{
45*/
46
47/** \brief Object type backing call_once.
48
49 This object type holds a flag that is used by the call_once function to call
50 a function one time. It should always be initialized with the ONCE_FLAG_INIT
51 macro.
52
53 \headerfile machine/_threads.h
54*/
56
57/** \brief Macro to initialize a once_flag object. */
58#define ONCE_FLAG_INIT KTHREAD_ONCE_INIT
59
60/** \brief C11 mutual exclusion lock type.
61
62 This type holds an identifier for a mutual exclusion (mutex) lock to be used
63 with C11 threading support.
64
65 \headerfile machine/_threads.h
66*/
67typedef mutex_t mtx_t;
68
69/** \brief C11 condition variable type.
70
71 This type holds an identifier for a condition variable object that is to be
72 used with C11 threading support.
73
74 \headerfile machine/_threads.h
75*/
77
78/** \brief C11 thread identifier type.
79
80 This type holds an identifier for a C11 thread.
81
82 \headerfile machine/_threads.h
83*/
85
86
87/** \brief Maximum number of iterations over TSS destructors.
88
89 This macro defines the maximum number of iterations that will be performed
90 over the destructors for thread-specific storage objects when a thread
91 terminates.
92
93 \headerfile machine/_threads.h
94*/
95#define TSS_DTOR_ITERATIONS 1
96
97/** \brief C11 thread-specific storage type.
98
99 This type holds a thread-specific storage identifier, which allows a value
100 to be associated with it for each and every thread running.
101
102 \headerfile machine/_threads.h
103*/
105
106/** @} */
107
108__END_DECLS
109
110#endif /* !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 201112L) */
111
112#endif /* !__MACHINE_THREADS_H */
Condition variables.
kthread_once_t once_flag
Object type backing call_once.
Definition _threads.h:55
condvar_t cnd_t
C11 condition variable type.
Definition _threads.h:76
mutex_t mtx_t
C11 mutual exclusion lock type.
Definition _threads.h:67
kthread_t * thrd_t
C11 thread identifier type.
Definition _threads.h:84
kthread_key_t tss_t
C11 thread-specific storage type.
Definition _threads.h:104
Mutual exclusion locks.
Dynamic package initialization.
volatile int kthread_once_t
Object type backing kthread_once.
Definition once.h:35
Condition variable.
Definition cond.h:60
Structure describing one running thread.
Definition thread.h:164
Mutual exclusion lock type.
Definition mutex.h:56
Threading support.
KOS-implementation of select C11 and POSIX extensions.
Thread-local storage support.
int kthread_key_t
Thread-local storage key type.
Definition tls.h:28