diff src/thread/win32/SDL_systhread.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 14717b52abc0
children 4da1ee79c9af
line wrap: on
line diff
--- a/src/thread/win32/SDL_systhread.c	Sun May 21 17:27:13 2006 +0000
+++ b/src/thread/win32/SDL_systhread.c	Sun May 28 13:04:16 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: */