21#include "../../SDL_internal.h"
29#include "../SDL_thread_c.h"
30#include "../SDL_systhread.h"
31#include "SDL_systhread_c.h"
33#ifndef SDL_PASSED_BEGINTHREAD_ENDTHREAD
37#ifndef STACK_SIZE_PARAM_IS_A_RESERVATION
38#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
42#if (defined(__MINGW32__) && (__GNUC__ < 4))
43typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (
void *, unsigned,
44 unsigned (__stdcall *
func)(
void *),
void *arg,
45 unsigned,
unsigned *threadID);
46typedef void (__cdecl *pfnSDL_CurrentEndThread)(
unsigned code);
48#elif defined(__WATCOMC__)
53typedef unsigned long (__watcall * pfnSDL_CurrentBeginThread) (
void *,
63typedef void (__watcall * pfnSDL_CurrentEndThread) (
unsigned code);
66typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (
void *, unsigned,
72typedef void (__cdecl * pfnSDL_CurrentEndThread) (
unsigned code);
77typedef struct ThreadStartParms
80 pfnSDL_CurrentEndThread pfnCurrentEndThread;
81} tThreadStartParms, *pThreadStartParms;
86 pThreadStartParms pThreadParms = (pThreadStartParms)
data;
87 pfnSDL_CurrentEndThread pfnEndThread = pThreadParms->pfnCurrentEndThread;
88 void *args = pThreadParms->args;
91 if (pfnEndThread !=
NULL)
97RunThreadViaCreateThread(LPVOID
data)
102static unsigned __stdcall
103RunThreadViaBeginThreadEx(
void *
data)
108#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
111 pfnSDL_CurrentBeginThread pfnBeginThread,
112 pfnSDL_CurrentEndThread pfnEndThread)
114#elif defined(__CYGWIN__) || defined(__WINRT__)
118 pfnSDL_CurrentBeginThread pfnBeginThread =
NULL;
119 pfnSDL_CurrentEndThread pfnEndThread =
NULL;
124 pfnSDL_CurrentBeginThread pfnBeginThread = (pfnSDL_CurrentBeginThread)_beginthreadex;
125 pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread)_endthreadex;
127 pThreadStartParms pThreadParms =
128 (pThreadStartParms)
SDL_malloc(
sizeof(tThreadStartParms));
129 const DWORD
flags = thread->
stacksize ? STACK_SIZE_PARAM_IS_A_RESERVATION : 0;
134 pThreadParms->pfnCurrentEndThread = pfnEndThread;
136 pThreadParms->args = args;
139 if (pfnBeginThread) {
140 unsigned threadid = 0;
142 ((
size_t) pfnBeginThread(
NULL, (
unsigned int) thread->
stacksize,
143 RunThreadViaBeginThreadEx,
144 pThreadParms,
flags, &threadid));
148 RunThreadViaCreateThread,
149 pThreadParms,
flags, &threadid);
152 return SDL_SetError(
"Not enough resources to create thread");
158typedef struct tagTHREADNAME_INFO
168typedef HRESULT (WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR);
175 static pfnSetThreadDescription pSetThreadDescription =
NULL;
176 static HMODULE kernel32 = 0;
179 kernel32 = LoadLibraryW(L
"kernel32.dll");
181 pSetThreadDescription = (pfnSetThreadDescription) GetProcAddress(kernel32,
"SetThreadDescription");
185 if (pSetThreadDescription !=
NULL) {
188 pSetThreadDescription(GetCurrentThread(), strw);
198 if (IsDebuggerPresent()) {
210 inf.dwThreadID = (DWORD) -1;
214 RaiseException(0x406D1388, 0,
sizeof(inf) /
sizeof(ULONG), (
const ULONG_PTR*) &inf);
231 value = THREAD_PRIORITY_LOWEST;
233 value = THREAD_PRIORITY_HIGHEST;
235 value = THREAD_PRIORITY_TIME_CRITICAL;
237 value = THREAD_PRIORITY_NORMAL;
239 if (!SetThreadPriority(GetCurrentThread(),
value)) {
248 WaitForSingleObjectEx(thread->
handle, INFINITE,
FALSE);
249 CloseHandle(thread->
handle);
255 CloseHandle(thread->
handle);
#define SDL_GetHintBoolean
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
#define SDL_OutOfMemory()
#define SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING
Tell SDL not to name threads on Windows with the 0x406D1388 Exception. The 0x406D1388 Exception is a ...
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLuint const GLchar * name
GLsizei const GLfloat * value
void SDL_RunThread(void *data)
unsigned long SDL_threadID
@ SDL_THREAD_PRIORITY_TIME_CRITICAL
@ SDL_THREAD_PRIORITY_LOW
@ SDL_THREAD_PRIORITY_HIGH
#define WIN_UTF8ToString(S)
int WIN_SetError(const char *prefix)
void SDL_SYS_SetupThread(const char *name)
void SDL_SYS_DetachThread(SDL_Thread *thread)
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
void SDL_SYS_WaitThread(SDL_Thread *thread)
SDL_threadID SDL_ThreadID(void)
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
static void * RunThread(void *data)