diff options
author | Sam Lantinga <slouken@libsdl.org> | 2012-02-20 23:51:08 -0500 |
---|---|---|
committer | Sam Lantinga <slouken@libsdl.org> | 2012-02-20 23:51:08 -0500 |
commit | 8d1c8c6df90dea84619cc7642eadbf9c34ef9c1e (patch) | |
tree | b56ca513528f69b459a8b91f6f3c2fb28d0241c9 | |
parent | e4b34e1345f6abce55a5d7f0b4bfd6b5d2aac5cd (diff) | |
download | sdl-8d1c8c6df90dea84619cc7642eadbf9c34ef9c1e.tar.gz |
Fixed bug 1426 - SDL_SemWaitTimeout returns -1 and sets error instead of SDL_MUTEX_TIMEDOUT on time out
deraj 2012-02-19 19:01:08 PST
Fix to treat ETIMEDOUT as a time out instead of an error (and update the test)
-rw-r--r-- | src/thread/pthread/SDL_syssem.c | 10 | ||||
-rw-r--r-- | test/testsem.c | 7 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index a03870fa3..4399a34ad 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -144,8 +144,14 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) retval = sem_timedwait(&sem->sem, &ts_timeout); while (retval == -1 && errno == EINTR); - if (retval == -1) - SDL_SetError(strerror(errno)); + if (retval == -1) { + if (errno == ETIMEDOUT) { + retval = SDL_MUTEX_TIMEDOUT; + } + else { + SDL_SetError(strerror(errno)); + } + } #else end = SDL_GetTicks() + timeout; while ((retval = SDL_SemTryWait(sem)) == SDL_MUTEX_TIMEDOUT) { diff --git a/test/testsem.c b/test/testsem.c index c906432b1..4d7f43ce8 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -38,12 +38,13 @@ static void TestWaitTimeout(void) Uint32 start_ticks; Uint32 end_ticks; Uint32 duration; + int retval; sem = SDL_CreateSemaphore(0); printf("Waiting 2 seconds on semaphore\n"); start_ticks = SDL_GetTicks(); - SDL_SemWaitTimeout(sem, 2000); + retval = SDL_SemWaitTimeout(sem, 2000); end_ticks = SDL_GetTicks(); duration = end_ticks - start_ticks; @@ -53,6 +54,10 @@ static void TestWaitTimeout(void) printf("Wait done.\n"); else fprintf(stderr, "Wait took %d milliseconds\n", duration); + + /* Check to make sure the return value indicates timed out */ + if (retval != SDL_MUTEX_TIMEDOUT) + fprintf(stderr, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT); } int main(int argc, char **argv) |