Mercurial > sdl-ios-xcode
comparison src/thread/linux/SDL_syssem.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 | c9b51268668f |
children | 604d73db6802 |
comparison
equal
deleted
inserted
replaced
1335:c39265384763 | 1336:3692456e7b0f |
---|---|
66 }; | 66 }; |
67 | 67 |
68 /* Create a semaphore, initialized with value */ | 68 /* Create a semaphore, initialized with value */ |
69 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | 69 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) |
70 { | 70 { |
71 SDL_sem *sem = (SDL_sem *) malloc(sizeof(SDL_sem)); | 71 SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem)); |
72 if ( sem ) { | 72 if ( sem ) { |
73 #ifdef USE_NAMED_SEMAPHORES | 73 #ifdef USE_NAMED_SEMAPHORES |
74 static int semnum = 0; | 74 static int semnum = 0; |
75 char name[32]; | 75 char name[32]; |
76 | 76 |
77 sprintf(name, "/SDL_sem-%d-%4.4d", getpid(), semnum++); | 77 sprintf(name, "/SDL_sem-%d-%4.4d", getpid(), semnum++); |
78 sem->sem = sem_open(name, O_CREAT, 0600, initial_value); | 78 sem->sem = sem_open(name, O_CREAT, 0600, initial_value); |
79 if ( sem->sem == (sem_t *)SEM_FAILED ) { | 79 if ( sem->sem == (sem_t *)SEM_FAILED ) { |
80 SDL_SetError("sem_open(%s) failed", name); | 80 SDL_SetError("sem_open(%s) failed", name); |
81 free(sem); | 81 SDL_free(sem); |
82 sem = NULL; | 82 sem = NULL; |
83 } else { | 83 } else { |
84 sem_unlink(name); | 84 sem_unlink(name); |
85 } | 85 } |
86 #else | 86 #else |
87 if ( sem_init(&sem->sem_data, 0, initial_value) < 0 ) { | 87 if ( sem_init(&sem->sem_data, 0, initial_value) < 0 ) { |
88 SDL_SetError("sem_init() failed"); | 88 SDL_SetError("sem_init() failed"); |
89 free(sem); | 89 SDL_free(sem); |
90 sem = NULL; | 90 sem = NULL; |
91 } else { | 91 } else { |
92 sem->sem = &sem->sem_data; | 92 sem->sem = &sem->sem_data; |
93 } | 93 } |
94 #endif /* USE_NAMED_SEMAPHORES */ | 94 #endif /* USE_NAMED_SEMAPHORES */ |
104 #ifdef USE_NAMED_SEMAPHORES | 104 #ifdef USE_NAMED_SEMAPHORES |
105 sem_close(sem->sem); | 105 sem_close(sem->sem); |
106 #else | 106 #else |
107 sem_destroy(sem->sem); | 107 sem_destroy(sem->sem); |
108 #endif | 108 #endif |
109 free(sem); | 109 SDL_free(sem); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 int SDL_SemTryWait(SDL_sem *sem) | 113 int SDL_SemTryWait(SDL_sem *sem) |
114 { | 114 { |
243 extern int _creating_thread_lock; /* SDL_threads.c */ | 243 extern int _creating_thread_lock; /* SDL_threads.c */ |
244 SDL_sem *sem; | 244 SDL_sem *sem; |
245 union semun init; | 245 union semun init; |
246 key_t key; | 246 key_t key; |
247 | 247 |
248 sem = (SDL_sem *)malloc(sizeof(*sem)); | 248 sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); |
249 if ( sem == NULL ) { | 249 if ( sem == NULL ) { |
250 SDL_OutOfMemory(); | 250 SDL_OutOfMemory(); |
251 return(NULL); | 251 return(NULL); |
252 } | 252 } |
253 /* This flag is true if we are creating the thread manager sem, | 253 /* This flag is true if we are creating the thread manager sem, |
267 } while ((sem->id < 0) && (key != IPC_PRIVATE) && (errno == EACCES)); | 267 } while ((sem->id < 0) && (key != IPC_PRIVATE) && (errno == EACCES)); |
268 | 268 |
269 /* Report the error if we eventually failed */ | 269 /* Report the error if we eventually failed */ |
270 if ( sem->id < 0 ) { | 270 if ( sem->id < 0 ) { |
271 SDL_SetError("Couldn't create semaphore"); | 271 SDL_SetError("Couldn't create semaphore"); |
272 free(sem); | 272 SDL_free(sem); |
273 return(NULL); | 273 return(NULL); |
274 } | 274 } |
275 init.val = initial_value; /* Initialize semaphore */ | 275 init.val = initial_value; /* Initialize semaphore */ |
276 semctl(sem->id, 0, SETVAL, init); | 276 semctl(sem->id, 0, SETVAL, init); |
277 return(sem); | 277 return(sem); |
285 #else | 285 #else |
286 union semun dummy; | 286 union semun dummy; |
287 dummy.val = 0; | 287 dummy.val = 0; |
288 semctl(sem->id, 0, IPC_RMID, dummy); | 288 semctl(sem->id, 0, IPC_RMID, dummy); |
289 #endif | 289 #endif |
290 free(sem); | 290 SDL_free(sem); |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 int SDL_SemTryWait(SDL_sem *sem) | 294 int SDL_SemTryWait(SDL_sem *sem) |
295 { | 295 { |