Mercurial > sdl-ios-xcode
diff src/thread/win32/SDL_systhread.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | 290b5baf2fca |
children | 4436464c4f51 |
line wrap: on
line diff
--- a/src/thread/win32/SDL_systhread.c Thu Jul 06 18:01:37 2006 +0000 +++ b/src/thread/win32/SDL_systhread.c Mon Jul 10 21:04:37 2006 +0000 @@ -37,114 +37,141 @@ #endif #if __GNUC__ -typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned, - unsigned (__stdcall *func)(void *), void *arg, - unsigned, unsigned *threadID); -typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code); +typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, + unsigned + (__stdcall * + func) (void *), + void *arg, + unsigned, + unsigned + *threadID); +typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); #elif defined(__WATCOMC__) /* This is for Watcom targets except OS2 */ #if __WATCOMC__ < 1240 #define __watcall #endif -typedef unsigned long (__watcall *pfnSDL_CurrentBeginThread) (void *, unsigned, - unsigned (__stdcall *func)(void *), void *arg, - unsigned, unsigned *threadID); -typedef void (__watcall *pfnSDL_CurrentEndThread)(unsigned code); +typedef unsigned long (__watcall * pfnSDL_CurrentBeginThread) (void *, + unsigned, + unsigned + (__stdcall * + func) (void + *), + void *arg, + unsigned, + unsigned + *threadID); +typedef void (__watcall * pfnSDL_CurrentEndThread) (unsigned code); #else -typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned, - unsigned (__stdcall *func)(void *), void *arg, - unsigned, unsigned *threadID); -typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code); +typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, + unsigned (__stdcall * + func) (void + *), + void *arg, unsigned, + unsigned *threadID); +typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); #endif #endif /* !SDL_PASSED_BEGINTHREAD_ENDTHREAD */ typedef struct ThreadStartParms { - void *args; - pfnSDL_CurrentEndThread pfnCurrentEndThread; + void *args; + pfnSDL_CurrentEndThread pfnCurrentEndThread; } tThreadStartParms, *pThreadStartParms; -static unsigned __stdcall RunThread(void *data) +static unsigned __stdcall +RunThread(void *data) { - pThreadStartParms pThreadParms = (pThreadStartParms)data; - pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL; + pThreadStartParms pThreadParms = (pThreadStartParms) data; + pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL; - // Call the thread function! - SDL_RunThread(pThreadParms->args); + // Call the thread function! + SDL_RunThread(pThreadParms->args); - // Get the current endthread we have to use! - if (pThreadParms) - { - pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread; - SDL_free(pThreadParms); - } - // Call endthread! - if (pfnCurrentEndThread) - (*pfnCurrentEndThread)(0); - return(0); + // Get the current endthread we have to use! + if (pThreadParms) { + pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread; + SDL_free(pThreadParms); + } + // Call endthread! + if (pfnCurrentEndThread) + (*pfnCurrentEndThread) (0); + return (0); } #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) +int +SDL_SYS_CreateThread(SDL_Thread * thread, void *args, + pfnSDL_CurrentBeginThread pfnBeginThread, + pfnSDL_CurrentEndThread pfnEndThread) { #else -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +int +SDL_SYS_CreateThread(SDL_Thread * thread, void *args) { #ifdef _WIN32_WCE - pfnSDL_CurrentBeginThread pfnBeginThread = NULL; - pfnSDL_CurrentEndThread pfnEndThread = NULL; + pfnSDL_CurrentBeginThread pfnBeginThread = NULL; + pfnSDL_CurrentEndThread pfnEndThread = NULL; #else - pfnSDL_CurrentBeginThread pfnBeginThread = _beginthreadex; - pfnSDL_CurrentEndThread pfnEndThread = _endthreadex; + pfnSDL_CurrentBeginThread pfnBeginThread = _beginthreadex; + pfnSDL_CurrentEndThread pfnEndThread = _endthreadex; #endif #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */ - unsigned threadid; - pThreadStartParms pThreadParms = (pThreadStartParms)SDL_malloc(sizeof(tThreadStartParms)); - if (!pThreadParms) { - SDL_OutOfMemory(); - return(-1); - } - - // Save the function which we will have to call to clear the RTL of calling app! - pThreadParms->pfnCurrentEndThread = pfnEndThread; - // Also save the real parameters we have to pass to thread function - pThreadParms->args = args; + unsigned threadid; + pThreadStartParms pThreadParms = + (pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms)); + if (!pThreadParms) { + SDL_OutOfMemory(); + return (-1); + } + // Save the function which we will have to call to clear the RTL of calling app! + pThreadParms->pfnCurrentEndThread = pfnEndThread; + // Also save the real parameters we have to pass to thread function + pThreadParms->args = args; - if (pfnBeginThread) { - thread->handle = (SYS_ThreadHandle) pfnBeginThread(NULL, 0, RunThread, - pThreadParms, 0, &threadid); - } else { - thread->handle = CreateThread(NULL, 0, RunThread, pThreadParms, 0, &threadid); - } - if (thread->handle == NULL) { - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - return(0); + if (pfnBeginThread) { + thread->handle = + (SYS_ThreadHandle) pfnBeginThread(NULL, 0, RunThread, + pThreadParms, 0, &threadid); + } else { + thread->handle = + CreateThread(NULL, 0, RunThread, pThreadParms, 0, &threadid); + } + if (thread->handle == NULL) { + SDL_SetError("Not enough resources to create thread"); + return (-1); + } + return (0); } -void SDL_SYS_SetupThread(void) +void +SDL_SYS_SetupThread(void) { - return; + return; } -Uint32 SDL_ThreadID(void) +Uint32 +SDL_ThreadID(void) { - return((Uint32)GetCurrentThreadId()); + return ((Uint32) GetCurrentThreadId()); } -void SDL_SYS_WaitThread(SDL_Thread *thread) +void +SDL_SYS_WaitThread(SDL_Thread * thread) { - WaitForSingleObject(thread->handle, INFINITE); - CloseHandle(thread->handle); + WaitForSingleObject(thread->handle, INFINITE); + CloseHandle(thread->handle); } /* WARNING: This function is really a last resort. * Threads should be signaled and then exit by themselves. * TerminateThread() doesn't perform stack and DLL cleanup. */ -void SDL_SYS_KillThread(SDL_Thread *thread) +void +SDL_SYS_KillThread(SDL_Thread * thread) { - TerminateThread(thread->handle, FALSE); + TerminateThread(thread->handle, FALSE); } + +/* vi: set ts=4 sw=4 expandtab: */