Mercurial > sdl-ios-xcode
comparison src/thread/linux/SDL_syssem.c @ 1300:fd068ab116ee
Removed some old Mac OS X cruft.
Fixes Bugzilla #64.
--ryan.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Mon, 30 Jan 2006 18:56:30 +0000 |
parents | b8d311d90021 |
children | c9b51268668f |
comparison
equal
deleted
inserted
replaced
1299:2bf9dda618e5 | 1300:fd068ab116ee |
---|---|
59 | 59 |
60 /* Wrapper around POSIX 1003.1b semaphores */ | 60 /* Wrapper around POSIX 1003.1b semaphores */ |
61 | 61 |
62 #ifdef MACOSX | 62 #ifdef MACOSX |
63 #define USE_NAMED_SEMAPHORES | 63 #define USE_NAMED_SEMAPHORES |
64 /* Broken sem_getvalue() in MacOS X Public Beta */ | |
65 #define BROKEN_SEMGETVALUE | |
66 #endif /* MACOSX */ | 64 #endif /* MACOSX */ |
67 | 65 |
68 struct SDL_semaphore { | 66 struct SDL_semaphore { |
69 sem_t *sem; | 67 sem_t *sem; |
70 #ifndef USE_NAMED_SEMAPHORES | 68 #ifndef USE_NAMED_SEMAPHORES |
71 sem_t sem_data; | 69 sem_t sem_data; |
72 #endif | |
73 #ifdef BROKEN_SEMGETVALUE | |
74 /* This is a little hack for MacOS X - | |
75 It's not thread-safe, but it's better than nothing | |
76 */ | |
77 int sem_value; | |
78 #endif | 70 #endif |
79 }; | 71 }; |
80 | 72 |
81 /* Create a semaphore, initialized with value */ | 73 /* Create a semaphore, initialized with value */ |
82 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | 74 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) |
103 sem = NULL; | 95 sem = NULL; |
104 } else { | 96 } else { |
105 sem->sem = &sem->sem_data; | 97 sem->sem = &sem->sem_data; |
106 } | 98 } |
107 #endif /* USE_NAMED_SEMAPHORES */ | 99 #endif /* USE_NAMED_SEMAPHORES */ |
108 | |
109 #ifdef BROKEN_SEMGETVALUE | |
110 if ( sem ) { | |
111 sem->sem_value = initial_value; | |
112 } | |
113 #endif /* BROKEN_SEMGETVALUE */ | |
114 } else { | 100 } else { |
115 SDL_OutOfMemory(); | 101 SDL_OutOfMemory(); |
116 } | 102 } |
117 return sem; | 103 return sem; |
118 } | 104 } |
137 SDL_SetError("Passed a NULL semaphore"); | 123 SDL_SetError("Passed a NULL semaphore"); |
138 return -1; | 124 return -1; |
139 } | 125 } |
140 retval = SDL_MUTEX_TIMEDOUT; | 126 retval = SDL_MUTEX_TIMEDOUT; |
141 if ( sem_trywait(sem->sem) == 0 ) { | 127 if ( sem_trywait(sem->sem) == 0 ) { |
142 #ifdef BROKEN_SEMGETVALUE | |
143 --sem->sem_value; | |
144 #endif | |
145 retval = 0; | 128 retval = 0; |
146 } | 129 } |
147 return retval; | 130 return retval; |
148 } | 131 } |
149 | 132 |
154 if ( ! sem ) { | 137 if ( ! sem ) { |
155 SDL_SetError("Passed a NULL semaphore"); | 138 SDL_SetError("Passed a NULL semaphore"); |
156 return -1; | 139 return -1; |
157 } | 140 } |
158 | 141 |
159 #ifdef BROKEN_SEMGETVALUE | |
160 --sem->sem_value; | |
161 #endif | |
162 retval = sem_wait(sem->sem); | 142 retval = sem_wait(sem->sem); |
163 if ( retval < 0 ) { | 143 if ( retval < 0 ) { |
164 SDL_SetError("sem_wait() failed"); | 144 SDL_SetError("sem_wait() failed"); |
165 } | 145 } |
166 return retval; | 146 return retval; |
198 | 178 |
199 Uint32 SDL_SemValue(SDL_sem *sem) | 179 Uint32 SDL_SemValue(SDL_sem *sem) |
200 { | 180 { |
201 int ret = 0; | 181 int ret = 0; |
202 if ( sem ) { | 182 if ( sem ) { |
203 #ifdef BROKEN_SEMGETVALUE | |
204 ret = sem->sem_value; | |
205 #else | |
206 sem_getvalue(sem->sem, &ret); | 183 sem_getvalue(sem->sem, &ret); |
207 #endif | |
208 if ( ret < 0 ) { | 184 if ( ret < 0 ) { |
209 ret = 0; | 185 ret = 0; |
210 } | 186 } |
211 } | 187 } |
212 return (Uint32)ret; | 188 return (Uint32)ret; |
219 if ( ! sem ) { | 195 if ( ! sem ) { |
220 SDL_SetError("Passed a NULL semaphore"); | 196 SDL_SetError("Passed a NULL semaphore"); |
221 return -1; | 197 return -1; |
222 } | 198 } |
223 | 199 |
224 #ifdef BROKEN_SEMGETVALUE | |
225 ++sem->sem_value; | |
226 #endif | |
227 retval = sem_post(sem->sem); | 200 retval = sem_post(sem->sem); |
228 if ( retval < 0 ) { | 201 if ( retval < 0 ) { |
229 SDL_SetError("sem_post() failed"); | 202 SDL_SetError("sem_post() failed"); |
230 } | 203 } |
231 return retval; | 204 return retval; |