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
64 
69 typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
70 
71 #if defined(__WIN32__) && !defined(HAVE_LIBC)
72 
92 #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
93 #include <process.h> /* _beginthreadex() and _endthreadex() */
94 
95 typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread)
96  (void *, unsigned, unsigned (__stdcall *func)(void *),
97  void * /*arg*/, unsigned, unsigned * /* threadID */);
98 typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
99 
103 extern DECLSPEC SDL_Thread *SDLCALL
104 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
105  pfnSDL_CurrentBeginThread pfnBeginThread,
106  pfnSDL_CurrentEndThread pfnEndThread);
107 
111 #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
112 #undef SDL_CreateThread
113 #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
114 #else
115 #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
116 #endif
117 
118 #elif defined(__OS2__)
119 /*
120  * just like the windows case above: We compile SDL2
121  * into a dll with Watcom's runtime statically linked.
122  */
123 #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
124 #ifndef __EMX__
125 #include <process.h>
126 #else
127 #include <stdlib.h>
128 #endif
129 typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void * /*arg*/);
130 typedef void (*pfnSDL_CurrentEndThread)(void);
131 extern DECLSPEC SDL_Thread *SDLCALL
132 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
133  pfnSDL_CurrentBeginThread pfnBeginThread,
134  pfnSDL_CurrentEndThread pfnEndThread);
135 #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
136 #undef SDL_CreateThread
137 #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
138 #else
139 #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
140 #endif
141 
142 #else
143 
162 extern DECLSPEC SDL_Thread *SDLCALL
163 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
164 
165 #endif
166 
174 extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
175 
179 extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
180 
186 extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
187 
191 extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
192 
211 extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
212 
239 extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
240 
271 extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
272 
283 extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
284 
297 extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
298 
299 
300 /* Ends C function definitions when using C++ */
301 #ifdef __cplusplus
302 }
303 #endif
304 #include "close_code.h"
305 
306 #endif /* SDL_thread_h_ */
307 
308 /* 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_threadID SDLCALL SDL_ThreadID(void)
DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread *thread)
int(SDLCALL * SDL_ThreadFunction)(void *data)
Definition: SDL_thread.h:69