My Project
Loading...
Searching...
No Matches
SDL_thread.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL_thread_h_
23#define SDL_thread_h_
24
31#include "SDL_stdinc.h"
32#include "SDL_error.h"
33
34/* Thread synchronization primitives */
35#include "SDL_atomic.h"
36#include "SDL_mutex.h"
37
38#if defined(__WIN32__) || defined(__GDK__)
39#include <process.h> /* _beginthreadex() and _endthreadex() */
40#endif
41#if defined(__OS2__) /* for _beginthread() and _endthread() */
42#ifndef __EMX__
43#include <process.h>
44#else
45#include <stdlib.h>
46#endif
47#endif
48
49#include "begin_code.h"
50/* Set up for C function definitions, even when using C++ */
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/* The SDL thread structure, defined in SDL_thread.c */
56struct SDL_Thread;
57typedef struct SDL_Thread SDL_Thread;
58
59/* The SDL thread ID */
60typedef unsigned long SDL_threadID;
61
62/* Thread local storage ID, 0 is the invalid ID */
63typedef unsigned int SDL_TLSID;
64
75typedef enum {
76 SDL_THREAD_PRIORITY_LOW,
77 SDL_THREAD_PRIORITY_NORMAL,
78 SDL_THREAD_PRIORITY_HIGH,
79 SDL_THREAD_PRIORITY_TIME_CRITICAL
81
88typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
89
90
91#if defined(__WIN32__) || defined(__GDK__)
112#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
113
114typedef uintptr_t (__cdecl * pfnSDL_CurrentBeginThread)
115 (void *, unsigned, unsigned (__stdcall *func)(void *),
116 void * /*arg*/, unsigned, unsigned * /* threadID */);
117typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
118
119#ifndef SDL_beginthread
120#define SDL_beginthread _beginthreadex
121#endif
122#ifndef SDL_endthread
123#define SDL_endthread _endthreadex
124#endif
125
126extern DECLSPEC SDL_Thread *SDLCALL
127SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
128 pfnSDL_CurrentBeginThread pfnBeginThread,
129 pfnSDL_CurrentEndThread pfnEndThread);
130
131extern DECLSPEC SDL_Thread *SDLCALL
133 const char *name, const size_t stacksize, void *data,
134 pfnSDL_CurrentBeginThread pfnBeginThread,
135 pfnSDL_CurrentEndThread pfnEndThread);
136
137
138#if defined(SDL_CreateThread) && SDL_DYNAMIC_API
139#undef SDL_CreateThread
140#define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
141#undef SDL_CreateThreadWithStackSize
142#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
143#else
144#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
145#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
146#endif
147
148#elif defined(__OS2__)
149/*
150 * just like the windows case above: We compile SDL2
151 * into a dll with Watcom's runtime statically linked.
152 */
153#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
154
155typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void * /*arg*/);
156typedef void (*pfnSDL_CurrentEndThread)(void);
157
158#ifndef SDL_beginthread
159#define SDL_beginthread _beginthread
160#endif
161#ifndef SDL_endthread
162#define SDL_endthread _endthread
163#endif
164
165extern DECLSPEC SDL_Thread *SDLCALL
166SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
167 pfnSDL_CurrentBeginThread pfnBeginThread,
168 pfnSDL_CurrentEndThread pfnEndThread);
169extern DECLSPEC SDL_Thread *SDLCALL
170SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data,
171 pfnSDL_CurrentBeginThread pfnBeginThread,
172 pfnSDL_CurrentEndThread pfnEndThread);
173
174#if defined(SDL_CreateThread) && SDL_DYNAMIC_API
175#undef SDL_CreateThread
176#define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
177#undef SDL_CreateThreadWithStackSize
178#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
179#else
180#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
181#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
182#endif
183
184#else
185
207extern DECLSPEC SDL_Thread *SDLCALL
208SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
209
253extern DECLSPEC SDL_Thread *SDLCALL
254SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data);
255
256#endif
257
272extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
273
290extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
291
307extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
308
322extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
323
357extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
358
393extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
394
408extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
409
422extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
423
447extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
448
454extern DECLSPEC void SDLCALL SDL_TLSCleanup(void);
455
456/* Ends C function definitions when using C++ */
457#ifdef __cplusplus
458}
459#endif
460#include "close_code.h"
461
462#endif /* SDL_thread_h_ */
463
464/* vi: set ts=4 sw=4 expandtab: */
DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread *thread)
DECLSPEC void *SDLCALL SDL_TLSGet(SDL_TLSID id)
DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void)
int(SDLCALL * SDL_ThreadFunction)(void *data)
Definition: SDL_thread.h:88
DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread)
DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void(SDLCALL *destructor)(void *))
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data)
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data)
DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void)
DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
SDL_ThreadPriority
Definition: SDL_thread.h:75
DECLSPEC void SDLCALL SDL_TLSCleanup(void)
DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority)
DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread *thread)