Mercurial > sdl-ios-xcode
comparison src/thread/os2/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 | 9ebbbb4ae53b |
children | 4436464c4f51 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
32 #include "../SDL_systhread.h" | 32 #include "../SDL_systhread.h" |
33 #include "../SDL_thread_c.h" | 33 #include "../SDL_thread_c.h" |
34 | 34 |
35 typedef struct ThreadStartParms | 35 typedef struct ThreadStartParms |
36 { | 36 { |
37 void *args; | 37 void *args; |
38 pfnSDL_CurrentEndThread pfnCurrentEndThread; | 38 pfnSDL_CurrentEndThread pfnCurrentEndThread; |
39 } tThreadStartParms, *pThreadStartParms; | 39 } tThreadStartParms, *pThreadStartParms; |
40 | 40 |
41 static void threadfunc(void *pparm) | 41 static void |
42 threadfunc(void *pparm) | |
42 { | 43 { |
43 pThreadStartParms pThreadParms = pparm; | 44 pThreadStartParms pThreadParms = pparm; |
44 pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL; | 45 pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL; |
45 | 46 |
46 // Call the thread function! | 47 // Call the thread function! |
47 SDL_RunThread(pThreadParms->args); | 48 SDL_RunThread(pThreadParms->args); |
48 | 49 |
49 // Get the current endthread we have to use! | 50 // Get the current endthread we have to use! |
50 if (pThreadParms) | 51 if (pThreadParms) { |
51 { | 52 pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread; |
52 pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread; | 53 SDL_free(pThreadParms); |
53 SDL_free(pThreadParms); | 54 } |
54 } | 55 // Call endthread! |
55 // Call endthread! | 56 if (pfnCurrentEndThread) |
56 if (pfnCurrentEndThread) | 57 (*pfnCurrentEndThread) (); |
57 (*pfnCurrentEndThread)(); | |
58 } | 58 } |
59 | 59 |
60 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) | 60 int |
61 SDL_SYS_CreateThread(SDL_Thread * thread, void *args, | |
62 pfnSDL_CurrentBeginThread pfnBeginThread, | |
63 pfnSDL_CurrentEndThread pfnEndThread) | |
61 { | 64 { |
62 pThreadStartParms pThreadParms = SDL_malloc(sizeof(tThreadStartParms)); | 65 pThreadStartParms pThreadParms = SDL_malloc(sizeof(tThreadStartParms)); |
63 if (!pThreadParms) | 66 if (!pThreadParms) { |
64 { | 67 SDL_SetError("Not enough memory to create thread"); |
65 SDL_SetError("Not enough memory to create thread"); | 68 return (-1); |
66 return(-1); | 69 } |
67 } | 70 // Save the function which we will have to call to clear the RTL of calling app! |
68 | 71 pThreadParms->pfnCurrentEndThread = pfnEndThread; |
69 // Save the function which we will have to call to clear the RTL of calling app! | 72 // Also save the real parameters we have to pass to thread function |
70 pThreadParms->pfnCurrentEndThread = pfnEndThread; | 73 pThreadParms->args = args; |
71 // Also save the real parameters we have to pass to thread function | 74 // Start the thread using the runtime library of calling app! |
72 pThreadParms->args = args; | 75 thread->threadid = thread->handle = |
73 // Start the thread using the runtime library of calling app! | 76 (*pfnBeginThread) (threadfunc, NULL, 512 * 1024, pThreadParms); |
74 thread->threadid = thread->handle = (*pfnBeginThread)(threadfunc, NULL, 512*1024, pThreadParms); | 77 if ((int) thread->threadid <= 0) { |
75 if ((int)thread->threadid <= 0) | 78 SDL_SetError("Not enough resources to create thread"); |
76 { | 79 return (-1); |
77 SDL_SetError("Not enough resources to create thread"); | 80 } |
78 return(-1); | 81 return (0); |
79 } | |
80 return(0); | |
81 } | 82 } |
82 | 83 |
83 void SDL_SYS_SetupThread(void) | 84 void |
85 SDL_SYS_SetupThread(void) | |
84 { | 86 { |
85 return; | 87 return; |
86 } | 88 } |
87 | 89 |
88 DECLSPEC Uint32 SDLCALL SDL_ThreadID(void) | 90 DECLSPEC Uint32 SDLCALL |
91 SDL_ThreadID(void) | |
89 { | 92 { |
90 PTIB tib; | 93 PTIB tib; |
91 DosGetInfoBlocks(&tib, NULL); | 94 DosGetInfoBlocks(&tib, NULL); |
92 return((Uint32) (tib->tib_ptib2->tib2_ultid)); | 95 return ((Uint32) (tib->tib_ptib2->tib2_ultid)); |
93 } | 96 } |
94 | 97 |
95 void SDL_SYS_WaitThread(SDL_Thread *thread) | 98 void |
99 SDL_SYS_WaitThread(SDL_Thread * thread) | |
96 { | 100 { |
97 TID tid = thread->handle; | 101 TID tid = thread->handle; |
98 DosWaitThread(&tid, DCWW_WAIT); | 102 DosWaitThread(&tid, DCWW_WAIT); |
99 } | 103 } |
100 | 104 |
101 /* WARNING: This function is really a last resort. | 105 /* WARNING: This function is really a last resort. |
102 * Threads should be signaled and then exit by themselves. | 106 * Threads should be signaled and then exit by themselves. |
103 * TerminateThread() doesn't perform stack and DLL cleanup. | 107 * TerminateThread() doesn't perform stack and DLL cleanup. |
104 */ | 108 */ |
105 void SDL_SYS_KillThread(SDL_Thread *thread) | 109 void |
110 SDL_SYS_KillThread(SDL_Thread * thread) | |
106 { | 111 { |
107 DosKillThread(thread->handle); | 112 DosKillThread(thread->handle); |
108 } | 113 } |
114 | |
115 /* vi: set ts=4 sw=4 expandtab: */ |