Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed bug 1426 - SDL_SemWaitTimeout returns -1 and sets error instead…
Browse files Browse the repository at this point in the history
… 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)
  • Loading branch information
slouken committed Feb 21, 2012
1 parent 30b17e7 commit 170ed57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/thread/pthread/SDL_syssem.c
Expand Up @@ -150,7 +150,11 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
} while (retval < 0 && errno == EINTR);

if (retval < 0) {
SDL_SetError("sem_timedwait() failed");
if (errno == ETIMEDOUT) {
retval = SDL_MUTEX_TIMEDOUT;
} else {
SDL_SetError(strerror(errno));
}
}
#else
end = SDL_GetTicks() + timeout;
Expand Down
7 changes: 6 additions & 1 deletion test/testsem.c
Expand Up @@ -56,12 +56,13 @@ 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;
Expand All @@ -71,6 +72,10 @@ 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
Expand Down

0 comments on commit 170ed57

Please sign in to comment.