2
Simple DirectMedia Layer
3
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
28
* Header for the SDL thread management routines.
31
#include "SDL_stdinc.h"
32
#include "SDL_error.h"
34
/* Thread synchronization primitives */
35
#include "SDL_mutex.h"
37
#include "begin_code.h"
38
/* Set up for C function definitions, even when using C++ */
45
/* The SDL thread structure, defined in SDL_thread.c */
47
typedef struct SDL_Thread SDL_Thread;
49
/* The SDL thread ID */
50
typedef unsigned long SDL_threadID;
52
/* The SDL thread priority
54
* Note: On many systems you require special privileges to set high priority.
57
SDL_THREAD_PRIORITY_LOW,
58
SDL_THREAD_PRIORITY_NORMAL,
59
SDL_THREAD_PRIORITY_HIGH
62
/* The function passed to SDL_CreateThread()
63
It is passed a void* user context parameter and returns an int.
65
typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
67
#if defined(__WIN32__) && !defined(HAVE_LIBC)
71
* We compile SDL into a DLL. This means, that it's the DLL which
72
* creates a new thread for the calling process with the SDL_CreateThread()
73
* API. There is a problem with this, that only the RTL of the SDL.DLL will
74
* be initialized for those threads, and not the RTL of the calling
77
* To solve this, we make a little hack here.
79
* We'll always use the caller's _beginthread() and _endthread() APIs to
80
* start a new thread. This way, if it's the SDL.DLL which uses this API,
81
* then the RTL of SDL.DLL will be used to create the new thread, and if it's
82
* the application, then the RTL of the application will be used.
85
* Always use the _beginthread() and _endthread() of the calling runtime
88
#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
90
#include <process.h> /* This has _beginthread() and _endthread() defined! */
94
typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
102
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
104
typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
105
unsigned (__stdcall *
110
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
116
extern DECLSPEC SDL_Thread *SDLCALL
117
SDL_CreateThread(SDL_ThreadFunction fn, void *data,
118
pfnSDL_CurrentBeginThread pfnBeginThread,
119
pfnSDL_CurrentEndThread pfnEndThread);
121
#if defined(_WIN32_WCE)
126
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, NULL, NULL)
133
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex)
141
extern DECLSPEC SDL_Thread *SDLCALL
142
SDL_CreateThread(SDL_ThreadFunction fn, void *data);
147
* Get the thread identifier for the current thread.
149
extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
152
* Get the thread identifier for the specified thread.
154
* Equivalent to SDL_ThreadID() if the specified thread is NULL.
156
extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
159
* Set the priority for the current thread
161
extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
164
* Wait for a thread to finish.
166
* The return code for the thread function is placed in the area
167
* pointed to by \c status, if \c status is not NULL.
169
extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
172
/* Ends C function definitions when using C++ */
178
#include "close_code.h"
180
#endif /* _SDL_thread_h */
182
/* vi: set ts=4 sw=4 expandtab: */