My Project
SDL_thread.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2018 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 
59 typedef enum {
60  SDL_THREAD_PRIORITY_LOW,
61  SDL_THREAD_PRIORITY_NORMAL,
62  SDL_THREAD_PRIORITY_HIGH,
63  SDL_THREAD_PRIORITY_TIME_CRITICAL
65 
70 typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
71 
72 #if defined(__WIN32__) && !defined(HAVE_LIBC)
73 
93 #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
94 #include <process.h> /* _beginthreadex() and _endthreadex() */
95 
96 typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread)
97  (void *, unsigned, unsigned (__stdcall *func)(void *),
98  void * /*arg*/, unsigned, unsigned * /* threadID */);
99 typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
100 
104 extern DECLSPEC SDL_Thread *SDLCALL
105 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
106  pfnSDL_CurrentBeginThread pfnBeginThread,
107  pfnSDL_CurrentEndThread pfnEndThread);
108 
109 extern DECLSPEC SDL_Thread *SDLCALL
110 SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
111  const char *name, const size_t stacksize, void *data,
112  pfnSDL_CurrentBeginThread pfnBeginThread,
113  pfnSDL_CurrentEndThread pfnEndThread);
114 
115 
119 #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
120 #undef SDL_CreateThread
121 #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
122 #undef SDL_CreateThreadWithStackSize
123 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
124 #else
125 #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
126 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
127 #endif
128 
129 #elif defined(__OS2__)
130 /*
131  * just like the windows case above: We compile SDL2
132  * into a dll with Watcom's runtime statically linked.
133  */
134 #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
135 #ifndef __EMX__
136 #include <process.h>
137 #else
138 #include <stdlib.h>
139 #endif
140 typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void * /*arg*/);
141 typedef void (*pfnSDL_CurrentEndThread)(void);
142 extern DECLSPEC SDL_Thread *SDLCALL
143 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
144  pfnSDL_CurrentBeginThread pfnBeginThread,
145  pfnSDL_CurrentEndThread pfnEndThread);
146 extern DECLSPEC SDL_Thread *SDLCALL
147 SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data,
148  pfnSDL_CurrentBeginThread pfnBeginThread,
149  pfnSDL_CurrentEndThread pfnEndThread);
150 #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
151 #undef SDL_CreateThread
152 #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
153 #undef SDL_CreateThreadWithStackSize
154 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
155 #else
156 #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
157 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
158 #endif
159 
160 #else
161 
168 extern DECLSPEC SDL_Thread *SDLCALL
169 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
170 
197 extern DECLSPEC SDL_Thread *SDLCALL
198 SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data);
199 
200 #endif
201 
209 extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
210 
214 extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
215 
221 extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
222 
226 extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
227 
246 extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
247 
274 extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
275 
306 extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
307 
318 extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
319 
332 extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
333 
334 
335 /* Ends C function definitions when using C++ */
336 #ifdef __cplusplus
337 }
338 #endif
339 #include "close_code.h"
340 
341 #endif /* SDL_thread_h_ */
342 
343 /* vi: set ts=4 sw=4 expandtab: */
DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority)
DECLSPEC void *SDLCALL SDL_TLSGet(SDL_TLSID id)
Get the value associated with a thread local storage ID for the current thread.
DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread)
SDL_ThreadPriority
Definition: SDL_thread.h:59
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.
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data)
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...
DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread *thread)
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data)
DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void)
DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread *thread)
int(SDLCALL * SDL_ThreadFunction)(void *data)
Definition: SDL_thread.h:70