comparison src/thread/generic/SDL_syssem.c @ 3287:77f2f10b81a7

Fixed bug #570 SDL_SemWaitTimeout in src/thread/generic/SDL_syssem.c line 179 (SVN trunk): --sem->count; should be if (retval == 0) { --sem->count; } Without this, sem->count will underflow on timeout effectively breaking the semaphore. It appears that the implementation has been wrong since the initial revision.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 21 Sep 2009 07:35:06 +0000
parents 99210400e8b9
children f7b03b6838cb
comparison
equal deleted inserted replaced
3286:d390778b59c1 3287:77f2f10b81a7
174 while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) { 174 while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) {
175 retval = SDL_CondWaitTimeout(sem->count_nonzero, 175 retval = SDL_CondWaitTimeout(sem->count_nonzero,
176 sem->count_lock, timeout); 176 sem->count_lock, timeout);
177 } 177 }
178 --sem->waiters_count; 178 --sem->waiters_count;
179 --sem->count; 179 if (retval == 0) {
180 --sem->count;
181 }
180 SDL_UnlockMutex(sem->count_lock); 182 SDL_UnlockMutex(sem->count_lock);
181 183
182 return retval; 184 return retval;
183 } 185 }
184 186