Zycore
1.5.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Thread.h
Go to the documentation of this file.
1
/***************************************************************************************************
2
3
Zyan Core Library (Zycore-C)
4
5
Original Author : Florian Bernd
6
7
* Permission is hereby granted, free of charge, to any person obtaining a copy
8
* of this software and associated documentation files (the "Software"), to deal
9
* in the Software without restriction, including without limitation the rights
10
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
* copies of the Software, and to permit persons to whom the Software is
12
* furnished to do so, subject to the following conditions:
13
*
14
* The above copyright notice and this permission notice shall be included in all
15
* copies or substantial portions of the Software.
16
*
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
* SOFTWARE.
24
25
***************************************************************************************************/
26
31
32
#ifndef ZYCORE_API_THREAD_H
33
#define ZYCORE_API_THREAD_H
34
35
#include <
Zycore/Defines.h
>
36
#include <
Zycore/Status.h
>
37
38
#ifndef ZYAN_NO_LIBC
39
40
#ifdef __cplusplus
41
extern
"C"
{
42
#endif
43
44
/* ============================================================================================== */
45
/* Enums and types */
46
/* ============================================================================================== */
47
48
#if defined(ZYAN_POSIX)
49
50
#include <pthread.h>
51
52
/* ---------------------------------------------------------------------------------------------- */
53
/* General */
54
/* ---------------------------------------------------------------------------------------------- */
55
59
typedef
pthread_t ZyanThread;
60
64
typedef
ZyanU64 ZyanThreadId;
65
66
/* ---------------------------------------------------------------------------------------------- */
67
/* Thread Local Storage (TLS) */
68
/* ---------------------------------------------------------------------------------------------- */
69
73
typedef
pthread_key_t ZyanThreadTlsIndex;
74
78
typedef
void(*ZyanThreadTlsCallback)(
void
* data);
79
87
#define ZYAN_THREAD_DECLARE_TLS_CALLBACK(name, param_type, param_name) \
88
void name(param_type* param_name)
89
90
/* ---------------------------------------------------------------------------------------------- */
91
92
#elif defined(ZYAN_WINDOWS)
93
94
#include <windows.h>
95
96
/* ---------------------------------------------------------------------------------------------- */
97
/* General */
98
/* ---------------------------------------------------------------------------------------------- */
99
103
typedef
HANDLE ZyanThread;
104
108
typedef
DWORD ZyanThreadId;
109
110
/* ---------------------------------------------------------------------------------------------- */
111
/* Thread Local Storage (TLS) */
112
/* ---------------------------------------------------------------------------------------------- */
113
117
typedef
DWORD ZyanThreadTlsIndex;
118
122
typedef
PFLS_CALLBACK_FUNCTION ZyanThreadTlsCallback;
123
131
#define ZYAN_THREAD_DECLARE_TLS_CALLBACK(name, param_type, param_name) \
132
VOID NTAPI name(param_type* param_name)
133
134
/* ---------------------------------------------------------------------------------------------- */
135
136
#else
137
# error "Unsupported platform detected"
138
#endif
139
140
/* ============================================================================================== */
141
/* Exported functions */
142
/* ============================================================================================== */
143
144
/* ---------------------------------------------------------------------------------------------- */
145
/* General */
146
/* ---------------------------------------------------------------------------------------------- */
147
155
ZYCORE_EXPORT
ZyanStatus
ZyanThreadGetCurrentThread
(ZyanThread* thread);
156
164
ZYCORE_EXPORT
ZyanStatus
ZyanThreadGetCurrentThreadId
(ZyanThreadId* thread_id);
165
166
/* ---------------------------------------------------------------------------------------------- */
167
/* Thread Local Storage (TLS) */
168
/* ---------------------------------------------------------------------------------------------- */
169
198
ZYCORE_EXPORT
ZyanStatus
ZyanThreadTlsAlloc
(ZyanThreadTlsIndex* index,
199
ZyanThreadTlsCallback destructor);
200
208
ZYCORE_EXPORT
ZyanStatus
ZyanThreadTlsFree
(ZyanThreadTlsIndex index);
209
220
ZYCORE_EXPORT
ZyanStatus
ZyanThreadTlsGetValue
(ZyanThreadTlsIndex index,
void
** data);
221
231
ZYCORE_EXPORT
ZyanStatus
ZyanThreadTlsSetValue
(ZyanThreadTlsIndex index,
void
* data);
232
233
/* ---------------------------------------------------------------------------------------------- */
234
235
/* ============================================================================================== */
236
237
#ifdef __cplusplus
238
}
239
#endif
240
241
#endif
/* ZYAN_NO_LIBC */
242
243
#endif
/* ZYCORE_API_THREAD_H */
Defines.h
ZYCORE_EXPORT
#define ZYCORE_EXPORT
Definition
Defines.h:235
Status.h
ZyanStatus
ZyanU32 ZyanStatus
Definition
Status.h:48
ZyanThreadTlsGetValue
ZYCORE_EXPORT ZyanStatus ZyanThreadTlsGetValue(ZyanThreadTlsIndex index, void **data)
ZyanThreadTlsSetValue
ZYCORE_EXPORT ZyanStatus ZyanThreadTlsSetValue(ZyanThreadTlsIndex index, void *data)
ZyanThreadTlsFree
ZYCORE_EXPORT ZyanStatus ZyanThreadTlsFree(ZyanThreadTlsIndex index)
ZyanThreadTlsAlloc
ZYCORE_EXPORT ZyanStatus ZyanThreadTlsAlloc(ZyanThreadTlsIndex *index, ZyanThreadTlsCallback destructor)
ZyanThreadGetCurrentThread
ZYCORE_EXPORT ZyanStatus ZyanThreadGetCurrentThread(ZyanThread *thread)
ZyanThreadGetCurrentThreadId
ZYCORE_EXPORT ZyanStatus ZyanThreadGetCurrentThreadId(ZyanThreadId *thread_id)
include
Zycore
API
Thread.h
Generated by
1.17.0