comparison src/thread/win32/SDL_systhread.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
61 unsigned, 61 unsigned,
62 unsigned 62 unsigned
63 *threadID); 63 *threadID);
64 typedef void (__watcall * pfnSDL_CurrentEndThread) (unsigned code); 64 typedef void (__watcall * pfnSDL_CurrentEndThread) (unsigned code);
65 #else 65 #else
66 typedef uintptr_t (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, 66 typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
67 unsigned (__stdcall * 67 unsigned (__stdcall *
68 func) (void 68 func) (void
69 *), 69 *),
70 void *arg, unsigned, 70 void *arg, unsigned,
71 unsigned *threadID); 71 unsigned *threadID);
72 typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); 72 typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
73 #endif 73 #endif
74 #endif /* !SDL_PASSED_BEGINTHREAD_ENDTHREAD */ 74 #endif /* !SDL_PASSED_BEGINTHREAD_ENDTHREAD */
75 75
76 76
79 void *args; 79 void *args;
80 pfnSDL_CurrentEndThread pfnCurrentEndThread; 80 pfnSDL_CurrentEndThread pfnCurrentEndThread;
81 } tThreadStartParms, *pThreadStartParms; 81 } tThreadStartParms, *pThreadStartParms;
82 82
83 static unsigned __stdcall 83 static unsigned __stdcall
84 RunThread (void *data) 84 RunThread(void *data)
85 { 85 {
86 pThreadStartParms pThreadParms = (pThreadStartParms) data; 86 pThreadStartParms pThreadParms = (pThreadStartParms) data;
87 pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL; 87 pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL;
88 88
89 // Call the thread function! 89 // Call the thread function!
90 SDL_RunThread (pThreadParms->args); 90 SDL_RunThread(pThreadParms->args);
91 91
92 // Get the current endthread we have to use! 92 // Get the current endthread we have to use!
93 if (pThreadParms) { 93 if (pThreadParms) {
94 pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread; 94 pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread;
95 SDL_free (pThreadParms); 95 SDL_free(pThreadParms);
96 } 96 }
97 // Call endthread! 97 // Call endthread!
98 if (pfnCurrentEndThread) 98 if (pfnCurrentEndThread)
99 (*pfnCurrentEndThread) (0); 99 (*pfnCurrentEndThread) (0);
100 return (0); 100 return (0);
101 } 101 }
102 102
103 #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD 103 #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
104 int 104 int
105 SDL_SYS_CreateThread (SDL_Thread * thread, void *args, 105 SDL_SYS_CreateThread(SDL_Thread * thread, void *args,
106 pfnSDL_CurrentBeginThread pfnBeginThread, 106 pfnSDL_CurrentBeginThread pfnBeginThread,
107 pfnSDL_CurrentEndThread pfnEndThread) 107 pfnSDL_CurrentEndThread pfnEndThread)
108 { 108 {
109 #else 109 #else
110 int 110 int
111 SDL_SYS_CreateThread (SDL_Thread * thread, void *args) 111 SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
112 { 112 {
113 #ifdef _WIN32_WCE 113 #ifdef _WIN32_WCE
114 pfnSDL_CurrentBeginThread pfnBeginThread = NULL; 114 pfnSDL_CurrentBeginThread pfnBeginThread = NULL;
115 pfnSDL_CurrentEndThread pfnEndThread = NULL; 115 pfnSDL_CurrentEndThread pfnEndThread = NULL;
116 #else 116 #else
118 pfnSDL_CurrentEndThread pfnEndThread = _endthreadex; 118 pfnSDL_CurrentEndThread pfnEndThread = _endthreadex;
119 #endif 119 #endif
120 #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */ 120 #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
121 unsigned threadid; 121 unsigned threadid;
122 pThreadStartParms pThreadParms = 122 pThreadStartParms pThreadParms =
123 (pThreadStartParms) SDL_malloc (sizeof (tThreadStartParms)); 123 (pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms));
124 if (!pThreadParms) { 124 if (!pThreadParms) {
125 SDL_OutOfMemory (); 125 SDL_OutOfMemory();
126 return (-1); 126 return (-1);
127 } 127 }
128 // Save the function which we will have to call to clear the RTL of calling app! 128 // Save the function which we will have to call to clear the RTL of calling app!
129 pThreadParms->pfnCurrentEndThread = pfnEndThread; 129 pThreadParms->pfnCurrentEndThread = pfnEndThread;
130 // Also save the real parameters we have to pass to thread function 130 // Also save the real parameters we have to pass to thread function
131 pThreadParms->args = args; 131 pThreadParms->args = args;
132 132
133 if (pfnBeginThread) { 133 if (pfnBeginThread) {
134 thread->handle = 134 thread->handle =
135 (SYS_ThreadHandle) pfnBeginThread (NULL, 0, RunThread, 135 (SYS_ThreadHandle) pfnBeginThread(NULL, 0, RunThread,
136 pThreadParms, 0, &threadid); 136 pThreadParms, 0, &threadid);
137 } else { 137 } else {
138 thread->handle = 138 thread->handle =
139 CreateThread (NULL, 0, RunThread, pThreadParms, 0, &threadid); 139 CreateThread(NULL, 0, RunThread, pThreadParms, 0, &threadid);
140 } 140 }
141 if (thread->handle == NULL) { 141 if (thread->handle == NULL) {
142 SDL_SetError ("Not enough resources to create thread"); 142 SDL_SetError("Not enough resources to create thread");
143 return (-1); 143 return (-1);
144 } 144 }
145 return (0); 145 return (0);
146 } 146 }
147 147
148 void 148 void
149 SDL_SYS_SetupThread (void) 149 SDL_SYS_SetupThread(void)
150 { 150 {
151 return; 151 return;
152 } 152 }
153 153
154 Uint32 154 Uint32
155 SDL_ThreadID (void) 155 SDL_ThreadID(void)
156 { 156 {
157 return ((Uint32) GetCurrentThreadId ()); 157 return ((Uint32) GetCurrentThreadId());
158 } 158 }
159 159
160 void 160 void
161 SDL_SYS_WaitThread (SDL_Thread * thread) 161 SDL_SYS_WaitThread(SDL_Thread * thread)
162 { 162 {
163 WaitForSingleObject (thread->handle, INFINITE); 163 WaitForSingleObject(thread->handle, INFINITE);
164 CloseHandle (thread->handle); 164 CloseHandle(thread->handle);
165 } 165 }
166 166
167 /* WARNING: This function is really a last resort. 167 /* WARNING: This function is really a last resort.
168 * Threads should be signaled and then exit by themselves. 168 * Threads should be signaled and then exit by themselves.
169 * TerminateThread() doesn't perform stack and DLL cleanup. 169 * TerminateThread() doesn't perform stack and DLL cleanup.
170 */ 170 */
171 void 171 void
172 SDL_SYS_KillThread (SDL_Thread * thread) 172 SDL_SYS_KillThread(SDL_Thread * thread)
173 { 173 {
174 TerminateThread (thread->handle, FALSE); 174 TerminateThread(thread->handle, FALSE);
175 } 175 }
176 176
177 /* vi: set ts=4 sw=4 expandtab: */ 177 /* vi: set ts=4 sw=4 expandtab: */