Mercurial > sdl-ios-xcode
comparison src/thread/generic/SDL_syssem.c @ 1627:aee7ea396f59
Fixed bug #179
SDL_SemValue() always returns 0. That's because the underlying POSIX
sem_getvalue() is implemented as a noop in Mac OS X. Apart from that,
semaphores do work properly (at least according to test/testsem), so I'm not
sure if this is worth fixing at all.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 13 Apr 2006 14:04:13 +0000 |
parents | d910939febfa |
children | 782fd950bd46 c121d94672cb a1b03ba2fcd0 |
comparison
equal
deleted
inserted
replaced
1626:a80e1e0880b8 | 1627:aee7ea396f59 |
---|---|
85 SDL_sem *sem; | 85 SDL_sem *sem; |
86 | 86 |
87 sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); | 87 sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); |
88 if ( ! sem ) { | 88 if ( ! sem ) { |
89 SDL_OutOfMemory(); | 89 SDL_OutOfMemory(); |
90 return(0); | 90 return NULL; |
91 } | 91 } |
92 sem->count = initial_value; | 92 sem->count = initial_value; |
93 sem->waiters_count = 0; | 93 sem->waiters_count = 0; |
94 | 94 |
95 sem->count_lock = SDL_CreateMutex(); | 95 sem->count_lock = SDL_CreateMutex(); |
96 sem->count_nonzero = SDL_CreateCond(); | 96 sem->count_nonzero = SDL_CreateCond(); |
97 if ( ! sem->count_lock || ! sem->count_nonzero ) { | 97 if ( ! sem->count_lock || ! sem->count_nonzero ) { |
98 SDL_DestroySemaphore(sem); | 98 SDL_DestroySemaphore(sem); |
99 return(0); | 99 return NULL; |
100 } | 100 } |
101 | 101 |
102 return(sem); | 102 return sem; |
103 } | 103 } |
104 | 104 |
105 /* WARNING: | 105 /* WARNING: |
106 You cannot call this function when another thread is using the semaphore. | 106 You cannot call this function when another thread is using the semaphore. |
107 */ | 107 */ |
112 while ( sem->waiters_count > 0) { | 112 while ( sem->waiters_count > 0) { |
113 SDL_CondSignal(sem->count_nonzero); | 113 SDL_CondSignal(sem->count_nonzero); |
114 SDL_Delay(10); | 114 SDL_Delay(10); |
115 } | 115 } |
116 SDL_DestroyCond(sem->count_nonzero); | 116 SDL_DestroyCond(sem->count_nonzero); |
117 SDL_mutexP(sem->count_lock); | 117 if ( sem->count_lock ) { |
118 SDL_mutexV(sem->count_lock); | 118 SDL_mutexP(sem->count_lock); |
119 SDL_DestroyMutex(sem->count_lock); | 119 SDL_mutexV(sem->count_lock); |
120 SDL_DestroyMutex(sem->count_lock); | |
121 } | |
120 SDL_free(sem); | 122 SDL_free(sem); |
121 } | 123 } |
122 } | 124 } |
123 | 125 |
124 int SDL_SemTryWait(SDL_sem *sem) | 126 int SDL_SemTryWait(SDL_sem *sem) |