comparison src/thread/SDL_thread.c @ 1336:3692456e7b0f

Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 06:59:48 +0000
parents 450721ad5436
children 604d73db6802
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
97 #ifdef DEBUG_THREADS 97 #ifdef DEBUG_THREADS
98 printf("Adding thread (%d already - %d max)\n", 98 printf("Adding thread (%d already - %d max)\n",
99 SDL_numthreads, SDL_maxthreads); 99 SDL_numthreads, SDL_maxthreads);
100 #endif 100 #endif
101 if ( SDL_numthreads == SDL_maxthreads ) { 101 if ( SDL_numthreads == SDL_maxthreads ) {
102 threads=(SDL_Thread **)malloc((SDL_maxthreads+ARRAY_CHUNKSIZE)* 102 threads=(SDL_Thread **)SDL_malloc((SDL_maxthreads+ARRAY_CHUNKSIZE)*
103 (sizeof *threads)); 103 (sizeof *threads));
104 if ( threads == NULL ) { 104 if ( threads == NULL ) {
105 SDL_OutOfMemory(); 105 SDL_OutOfMemory();
106 goto done; 106 goto done;
107 } 107 }
108 memcpy(threads, SDL_Threads, SDL_numthreads*(sizeof *threads)); 108 SDL_memcpy(threads, SDL_Threads, SDL_numthreads*(sizeof *threads));
109 SDL_maxthreads += ARRAY_CHUNKSIZE; 109 SDL_maxthreads += ARRAY_CHUNKSIZE;
110 if ( SDL_Threads ) { 110 if ( SDL_Threads ) {
111 free(SDL_Threads); 111 SDL_free(SDL_Threads);
112 } 112 }
113 SDL_Threads = threads; 113 SDL_Threads = threads;
114 } 114 }
115 SDL_Threads[SDL_numthreads++] = thread; 115 SDL_Threads[SDL_numthreads++] = thread;
116 done: 116 done:
134 SDL_Threads[i] = SDL_Threads[i+1]; 134 SDL_Threads[i] = SDL_Threads[i+1];
135 ++i; 135 ++i;
136 } 136 }
137 } else { 137 } else {
138 SDL_maxthreads = 0; 138 SDL_maxthreads = 0;
139 free(SDL_Threads); 139 SDL_free(SDL_Threads);
140 SDL_Threads = NULL; 140 SDL_Threads = NULL;
141 } 141 }
142 #ifdef DEBUG_THREADS 142 #ifdef DEBUG_THREADS
143 printf("Deleting thread (%d left - %d max)\n", 143 printf("Deleting thread (%d left - %d max)\n",
144 SDL_numthreads, SDL_maxthreads); 144 SDL_numthreads, SDL_maxthreads);
221 SDL_Thread *thread; 221 SDL_Thread *thread;
222 thread_args *args; 222 thread_args *args;
223 int ret; 223 int ret;
224 224
225 /* Allocate memory for the thread info structure */ 225 /* Allocate memory for the thread info structure */
226 thread = (SDL_Thread *)malloc(sizeof(*thread)); 226 thread = (SDL_Thread *)SDL_malloc(sizeof(*thread));
227 if ( thread == NULL ) { 227 if ( thread == NULL ) {
228 SDL_OutOfMemory(); 228 SDL_OutOfMemory();
229 return(NULL); 229 return(NULL);
230 } 230 }
231 memset(thread, 0, (sizeof *thread)); 231 SDL_memset(thread, 0, (sizeof *thread));
232 thread->status = -1; 232 thread->status = -1;
233 233
234 /* Set up the arguments for the thread */ 234 /* Set up the arguments for the thread */
235 args = (thread_args *)malloc(sizeof(*args)); 235 args = (thread_args *)SDL_malloc(sizeof(*args));
236 if ( args == NULL ) { 236 if ( args == NULL ) {
237 SDL_OutOfMemory(); 237 SDL_OutOfMemory();
238 free(thread); 238 SDL_free(thread);
239 return(NULL); 239 return(NULL);
240 } 240 }
241 args->func = fn; 241 args->func = fn;
242 args->data = data; 242 args->data = data;
243 args->info = thread; 243 args->info = thread;
244 args->wait = SDL_CreateSemaphore(0); 244 args->wait = SDL_CreateSemaphore(0);
245 if ( args->wait == NULL ) { 245 if ( args->wait == NULL ) {
246 free(thread); 246 SDL_free(thread);
247 free(args); 247 SDL_free(args);
248 return(NULL); 248 return(NULL);
249 } 249 }
250 250
251 /* Add the thread to the list of available threads */ 251 /* Add the thread to the list of available threads */
252 SDL_AddThread(thread); 252 SDL_AddThread(thread);
261 /* Wait for the thread function to use arguments */ 261 /* Wait for the thread function to use arguments */
262 SDL_SemWait(args->wait); 262 SDL_SemWait(args->wait);
263 } else { 263 } else {
264 /* Oops, failed. Gotta free everything */ 264 /* Oops, failed. Gotta free everything */
265 SDL_DelThread(thread); 265 SDL_DelThread(thread);
266 free(thread); 266 SDL_free(thread);
267 thread = NULL; 267 thread = NULL;
268 } 268 }
269 SDL_DestroySemaphore(args->wait); 269 SDL_DestroySemaphore(args->wait);
270 free(args); 270 SDL_free(args);
271 271
272 /* Everything is running now */ 272 /* Everything is running now */
273 return(thread); 273 return(thread);
274 } 274 }
275 275
279 SDL_SYS_WaitThread(thread); 279 SDL_SYS_WaitThread(thread);
280 if ( status ) { 280 if ( status ) {
281 *status = thread->status; 281 *status = thread->status;
282 } 282 }
283 SDL_DelThread(thread); 283 SDL_DelThread(thread);
284 free(thread); 284 SDL_free(thread);
285 } 285 }
286 } 286 }
287 287
288 Uint32 SDL_GetThreadID(SDL_Thread *thread) 288 Uint32 SDL_GetThreadID(SDL_Thread *thread)
289 { 289 {