My Project
SDL_thread.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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 #include "begin_code.h"
39 /* Set up for C function definitions, even when using C++ */
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /* The SDL thread structure, defined in SDL_thread.c */
45 struct SDL_Thread;
46 typedef struct SDL_Thread SDL_Thread;
47 
48 /* The SDL thread ID */
49 typedef unsigned long SDL_threadID;
50 
51 /* Thread local storage ID, 0 is the invalid ID */
52 typedef unsigned int SDL_TLSID;
53 
64 typedef enum {
65  SDL_THREAD_PRIORITY_LOW,
66  SDL_THREAD_PRIORITY_NORMAL,
67  SDL_THREAD_PRIORITY_HIGH,
68  SDL_THREAD_PRIORITY_TIME_CRITICAL
70 
75 typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
76 
77 #if defined(__WIN32__)
78 
98 #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
99 #include <process.h> /* _beginthreadex() and _endthreadex() */
100 
101 typedef uintptr_t (__cdecl * pfnSDL_CurrentBeginThread)
102  (void *, unsigned, unsigned (__stdcall *func)(void *),
103  void * /*arg*/, unsigned, unsigned * /* threadID */);
104 typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
105 
106 #ifndef SDL_beginthread
107 #define SDL_beginthread _beginthreadex
108 #endif
109 #ifndef SDL_endthread
110 #define SDL_endthread _endthreadex
111 #endif
112 
116 extern DECLSPEC SDL_Thread *SDLCALL
117 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
118  pfnSDL_CurrentBeginThread pfnBeginThread,
119  pfnSDL_CurrentEndThread pfnEndThread);
120 
121 extern DECLSPEC SDL_Thread *SDLCALL
122 SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
123  const char *name, const size_t stacksize, void *data,
124  pfnSDL_CurrentBeginThread pfnBeginThread,
125  pfnSDL_CurrentEndThread pfnEndThread);
126 
127 
131 #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
132 #undef SDL_CreateThread
133 #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
134 #undef SDL_CreateThreadWithStackSize
135 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
136 #else
137 #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
138 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)SDL_endthread)
139 #endif
140 
141 #elif defined(__OS2__)
142 /*
143  * just like the windows case above: We compile SDL2
144  * into a dll with Watcom's runtime statically linked.
145  */
146 #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
147 
148 #ifndef __EMX__
149 #include <process.h>
150 #else
151 #include <stdlib.h>
152 #endif
153 
154 typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void * /*arg*/);
155 typedef void (*pfnSDL_CurrentEndThread)(void);
156 
157 #ifndef SDL_beginthread
158 #define SDL_beginthread _beginthread
159 #endif
160 #ifndef SDL_endthread
161 #define SDL_endthread _endthread
162 #endif
163 
164 extern DECLSPEC SDL_Thread *SDLCALL
165 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
166  pfnSDL_CurrentBeginThread pfnBeginThread,
167  pfnSDL_CurrentEndThread pfnEndThread);
168 extern DECLSPEC SDL_Thread *SDLCALL
169 SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data,
170  pfnSDL_CurrentBeginThread pfnBeginThread,
171  pfnSDL_CurrentEndThread pfnEndThread);
172 
173 #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
174 #undef SDL_CreateThread
175 #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
176 #undef SDL_CreateThreadWithStackSize
177 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
178 #else
179 #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
180 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
181 #endif
182 
183 #else
184 
191 extern DECLSPEC SDL_Thread *SDLCALL
192 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
193 
220 extern DECLSPEC SDL_Thread *SDLCALL
221 SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data);
222 
223 #endif
224 
232 extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
233 
237 extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
238 
244 extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
245 
249 extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
250 
269 extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
270 
297 extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
298 
329 extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
330 
341 extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
342 
355 extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
356 
357 
358 /* Ends C function definitions when using C++ */
359 #ifdef __cplusplus
360 }
361 #endif
362 #include "close_code.h"
363 
364 #endif /* SDL_thread_h_ */
365 
366 /* vi: set ts=4 sw=4 expandtab: */
SDL_TLSCreate
DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void)
Create an identifier that is globally visible to all threads but refers to data that is thread-specif...
SDL_WaitThread
DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
SDL_TLSSet
DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void(SDLCALL *destructor)(void *))
Set the value associated with a thread local storage ID for the current thread.
SDL_DetachThread
DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread *thread)
SDL_atomic.h
SDL_ThreadFunction
int(SDLCALL * SDL_ThreadFunction)(void *data)
Definition: SDL_thread.h:75
SDL_stdinc.h
close_code.h
begin_code.h
SDL_ThreadID
DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void)
SDL_GetThreadID
DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread *thread)
SDL_ThreadPriority
SDL_ThreadPriority
Definition: SDL_thread.h:64
SDL_TLSGet
DECLSPEC void *SDLCALL SDL_TLSGet(SDL_TLSID id)
Get the value associated with a thread local storage ID for the current thread.
SDL_GetThreadName
DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread)
SDL_CreateThreadWithStackSize
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data)
SDL_SetThreadPriority
DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority)
SDL_mutex.h
SDL_error.h
SDL_CreateThread
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data)