21 #include "../../SDL_internal.h" 23 #if SDL_THREAD_WINDOWS 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)) 43 typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (
void *, unsigned,
44 unsigned (__stdcall *
func)(
void *),
void *arg,
45 unsigned,
unsigned *threadID);
46 typedef void (__cdecl *pfnSDL_CurrentEndThread)(
unsigned code);
48 #elif defined(__WATCOMC__) 50 #if __WATCOMC__ < 1240 53 typedef unsigned long (__watcall * pfnSDL_CurrentBeginThread) (
void *,
63 typedef void (__watcall * pfnSDL_CurrentEndThread) (
unsigned code);
66 typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (
void *, unsigned,
72 typedef void (__cdecl * pfnSDL_CurrentEndThread) (
unsigned code);
77 typedef 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)
97 RunThreadViaCreateThread(LPVOID data)
102 static unsigned __stdcall
103 RunThreadViaBeginThreadEx(
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");
158 typedef struct tagTHREADNAME_INFO
168 typedef 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_NORMAL;
237 if (!SetThreadPriority(GetCurrentThread(), value)) {
246 WaitForSingleObjectEx(thread->
handle, INFINITE,
FALSE);
247 CloseHandle(thread->
handle);
253 CloseHandle(thread->
handle);
#define WIN_UTF8ToString(S)
#define SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING
Tell SDL not to name threads on Windows with the 0x406D1388 Exception. The 0x406D1388 Exception is a ...
static void * RunThread(void *data)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLuint const GLchar * name
#define SDL_GetHintBoolean
SDL_threadID SDL_ThreadID(void)
void SDL_SYS_WaitThread(SDL_Thread *thread)
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
GLsizei const GLfloat * value
void SDL_SYS_DetachThread(SDL_Thread *thread)
#define SDL_OutOfMemory()
int WIN_SetError(const char *prefix)
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
void SDL_RunThread(void *data)
void SDL_SYS_SetupThread(const char *name)
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
unsigned long SDL_threadID