My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SDL_thread.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2016 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> /* This has _beginthread() and _endthread() defined! */
94 
95 typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
96  unsigned (__stdcall *
97  func) (void
98  *),
99  void *arg, unsigned,
100  unsigned *threadID);
101 typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
102 
106 extern DECLSPEC SDL_Thread *SDLCALL
107 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
108  pfnSDL_CurrentBeginThread pfnBeginThread,
109  pfnSDL_CurrentEndThread pfnEndThread);
110 
114 #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
115 #undef SDL_CreateThread
116 #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
117 #else
118 #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
119 #endif
120 
121 #else
122 
141 extern DECLSPEC SDL_Thread *SDLCALL
142 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
143 
144 #endif
145 
153 extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
154 
158 extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
159 
165 extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
166 
170 extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
171 
190 extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
191 
218 extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
219 
250 extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
251 
262 extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
263 
276 extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (*destructor)(void*));
277 
278 
279 /* Ends C function definitions when using C++ */
280 #ifdef __cplusplus
281 }
282 #endif
283 #include "close_code.h"
284 
285 #endif /* _SDL_thread_h */
286 
287 /* 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)
typedef int(SDLCALL *SDL_ThreadFunction)(void *data)
SDL_ThreadPriority
Definition: SDL_thread.h:59
typedef void(SDLCALL *SDL_AudioCallback)(void *userdata
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)
DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void(*destructor)(void *))
Set the value associated with a thread local storage ID for the current thread.