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-2013 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 #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
115 
116 #else
117 
136 extern DECLSPEC SDL_Thread *SDLCALL
137 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
138 
139 #endif
140 
148 extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
149 
153 extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
154 
160 extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
161 
165 extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
166 
173 extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
174 
205 extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
206 
217 extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
218 
231 extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (*destructor)(void*));
232 
233 
234 /* Ends C function definitions when using C++ */
235 #ifdef __cplusplus
236 }
237 #endif
238 #include "close_code.h"
239 
240 #endif /* _SDL_thread_h */
241 
242 /* vi: set ts=4 sw=4 expandtab: */
typedef int(SDLCALL *SDL_EventFilter)(void *userdata
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
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 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.