Mercurial > sdl-ios-xcode
comparison src/thread/win32/SDL_systhread.c @ 1330:450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
using Visual C++ 2005
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 06 Feb 2006 08:28:51 +0000 |
parents | c9b51268668f |
children | 3692456e7b0f |
comparison
equal
deleted
inserted
replaced
1329:bc67bbf87818 | 1330:450721ad5436 |
---|---|
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 | 22 |
23 /* Win32 thread management routines for SDL */ | 23 /* Win32 thread management routines for SDL */ |
24 | 24 |
25 #include <stdio.h> | 25 #include "SDL_windows.h" |
26 #include <stdlib.h> | |
27 #include <windows.h> | |
28 | |
29 #ifndef _WIN32_WCE | |
30 #include <process.h> | |
31 #endif | |
32 | 26 |
33 #include "SDL_error.h" | 27 #include "SDL_error.h" |
34 #include "SDL_thread.h" | 28 #include "SDL_thread.h" |
29 #include "SDL_stdlib.h" | |
35 #include "SDL_systhread.h" | 30 #include "SDL_systhread.h" |
36 | 31 |
32 typedef struct ThreadStartParms | |
33 { | |
34 void *args; | |
35 pfnSDL_CurrentEndThread pfnCurrentEndThread; | |
36 } tThreadStartParms, *pThreadStartParms; | |
37 | 37 |
38 static unsigned __stdcall RunThread(void *data) | 38 static unsigned __stdcall RunThread(void *data) |
39 { | 39 { |
40 SDL_RunThread(data); | 40 pThreadStartParms pThreadParms = (pThreadStartParms)data; |
41 return(0); | 41 pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL; |
42 | |
43 // Call the thread function! | |
44 SDL_RunThread(pThreadParms->args); | |
45 | |
46 // Get the current endthread we have to use! | |
47 if (pThreadParms) | |
48 { | |
49 pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread; | |
50 free(pThreadParms); | |
51 } | |
52 // Call endthread! | |
53 if (pfnCurrentEndThread) | |
54 (*pfnCurrentEndThread)(0); | |
55 return(0); | |
42 } | 56 } |
43 | 57 |
44 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) | 58 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) |
45 { | 59 { |
46 unsigned threadid; | 60 unsigned threadid; |
61 pThreadStartParms pThreadParms = (pThreadStartParms)malloc(sizeof(tThreadStartParms)); | |
62 if (!pThreadParms) { | |
63 SDL_OutOfMemory(); | |
64 return(-1); | |
65 } | |
47 | 66 |
48 /* | 67 // Save the function which we will have to call to clear the RTL of calling app! |
49 * Avoid CreateThread: https://bugzilla.libsdl.org/show_bug.cgi?id=22 | 68 pThreadParms->pfnCurrentEndThread = pfnEndThread; |
50 * | 69 // Also save the real parameters we have to pass to thread function |
51 * have to use _beginthreadex if we want the returned handle | 70 pThreadParms->args = args; |
52 * to be accessible after the thread exits | 71 |
53 * threads created with _beginthread auto-close the handle | 72 if (pfnBeginThread) { |
54 * Windows CE still use CreateThread. | 73 thread->handle = (SYS_ThreadHandle) pfnBeginThread(NULL, 0, RunThread, |
55 */ | 74 pThreadParms, 0, &threadid); |
56 #ifdef _WIN32_WCE | 75 } else { |
57 thread->handle = CreateThread(NULL, 0, RunThread, args, 0, &threadid); | 76 thread->handle = CreateThread(NULL, 0, RunThread, pThreadParms, 0, &threadid); |
58 #else | 77 } |
59 thread->handle = (SYS_ThreadHandle) _beginthreadex(NULL, 0, RunThread, | |
60 args, 0, &threadid); | |
61 #endif | |
62 if (thread->handle == NULL) { | 78 if (thread->handle == NULL) { |
63 SDL_SetError("Not enough resources to create thread"); | 79 SDL_SetError("Not enough resources to create thread"); |
64 return(-1); | 80 return(-1); |
65 } | 81 } |
66 return(0); | 82 return(0); |