World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
SDL_thread.h
См. документацию.
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 
59 typedef enum {
65 
70 typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
71 
72 #if defined(__WIN32__)
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 
101 #ifndef SDL_beginthread
102 #define SDL_beginthread _beginthreadex
103 #endif
104 #ifndef SDL_endthread
105 #define SDL_endthread _endthreadex
106 #endif
107 
111 extern DECLSPEC SDL_Thread *SDLCALL
112 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
113  pfnSDL_CurrentBeginThread pfnBeginThread,
114  pfnSDL_CurrentEndThread pfnEndThread);
115 
116 extern DECLSPEC SDL_Thread *SDLCALL
117 SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
118  const char *name, const size_t stacksize, void *data,
119  pfnSDL_CurrentBeginThread pfnBeginThread,
120  pfnSDL_CurrentEndThread pfnEndThread);
121 
122 
126 #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
127 #undef SDL_CreateThread
128 #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
129 #undef SDL_CreateThreadWithStackSize
130 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
131 #else
132 #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
133 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)SDL_endthread)
134 #endif
135 
136 #elif defined(__OS2__)
137 /*
138  * just like the windows case above: We compile SDL2
139  * into a dll with Watcom's runtime statically linked.
140  */
141 #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
142 
143 #ifndef __EMX__
144 #include <process.h>
145 #else
146 #include <stdlib.h>
147 #endif
148 
149 typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void * /*arg*/);
150 typedef void (*pfnSDL_CurrentEndThread)(void);
151 
152 #ifndef SDL_beginthread
153 #define SDL_beginthread _beginthread
154 #endif
155 #ifndef SDL_endthread
156 #define SDL_endthread _endthread
157 #endif
158 
159 extern DECLSPEC SDL_Thread *SDLCALL
160 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
161  pfnSDL_CurrentBeginThread pfnBeginThread,
162  pfnSDL_CurrentEndThread pfnEndThread);
163 extern DECLSPEC SDL_Thread *SDLCALL
164 SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data,
165  pfnSDL_CurrentBeginThread pfnBeginThread,
166  pfnSDL_CurrentEndThread pfnEndThread);
167 
168 #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
169 #undef SDL_CreateThread
170 #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
171 #undef SDL_CreateThreadWithStackSize
172 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
173 #else
174 #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
175 #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
176 #endif
177 
178 #else
179 
186 extern DECLSPEC SDL_Thread *SDLCALL
187 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
188 
215 extern DECLSPEC SDL_Thread *SDLCALL
216 SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data);
217 
218 #endif
219 
227 extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
228 
232 extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
233 
239 extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
240 
244 extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
245 
264 extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
265 
292 extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
293 
324 extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
325 
336 extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
337 
350 extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
351 
352 
353 /* Ends C function definitions when using C++ */
354 #ifdef __cplusplus
355 }
356 #endif
357 #include "close_code.h"
358 
359 #endif /* SDL_thread_h_ */
360 
361 /* vi: set ts=4 sw=4 expandtab: */
SDL_SetThreadPriority
DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority)
SDL_ThreadFunction
int(SDLCALL * SDL_ThreadFunction)(void *data)
Definition: SDL_thread.h:70
SDL_atomic.h
SDL_error.h
SDL_THREAD_PRIORITY_TIME_CRITICAL
@ SDL_THREAD_PRIORITY_TIME_CRITICAL
Definition: SDL_thread.h:63
SDL_THREAD_PRIORITY_HIGH
@ SDL_THREAD_PRIORITY_HIGH
Definition: SDL_thread.h:62
SDL_DetachThread
DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread *thread)
pfnSDL_CurrentEndThread
void(__cdecl * pfnSDL_CurrentEndThread)(unsigned code)
Definition: SDL_thread.h:99
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_THREAD_PRIORITY_LOW
@ SDL_THREAD_PRIORITY_LOW
Definition: SDL_thread.h:60
func
GLenum func
Definition: SDL_opengl_glext.h:660
SDL_TLSID
unsigned int SDL_TLSID
Definition: SDL_thread.h:52
close_code.h
begin_code.h
SDL_Thread
struct SDL_Thread SDL_Thread
Definition: SDL_thread.h:46
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_ThreadID
DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void)
SDL_mutex.h
value
EGLSyncKHR EGLint EGLint * value
Definition: SDL_egl.h:899
SDL_TLSGet
DECLSPEC void *SDLCALL SDL_TLSGet(SDL_TLSID id)
Get the value associated with a thread local storage ID for the current thread.
uintptr_t
unsigned __int64 uintptr_t
Definition: SDL_config.h:44
SDL_CreateThreadWithStackSize
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *), const char *name, const size_t stacksize, void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
SDL_GetThreadID
DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread *thread)
void
typedef void(SDLCALL *SDL_AudioFilter)(struct SDL_AudioCVT *cvt
SDL_threadID
unsigned long SDL_threadID
Definition: SDL_thread.h:49
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
name
EGLImageKHR EGLint * name
Definition: SDL_egl.h:1497
SDL_GetThreadName
const DECLSPEC char *SDLCALL SDL_GetThreadName(SDL_Thread *thread)
SDL_stdinc.h
SDL_THREAD_PRIORITY_NORMAL
@ SDL_THREAD_PRIORITY_NORMAL
Definition: SDL_thread.h:61
SDL_CreateThread
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
SDL_WaitThread
DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
SDL_ThreadPriority
SDL_ThreadPriority
Definition: SDL_thread.h:59
pfnSDL_CurrentBeginThread
uintptr_t(__cdecl * pfnSDL_CurrentBeginThread)(void *, unsigned, unsigned(__stdcall *func)(void *), void *, unsigned, unsigned *)
Definition: SDL_thread.h:97