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)
This commit is contained in:
parent
38463b3a0c
commit
099dd8f095
2 changed files with 11 additions and 2 deletions
|
@ -150,7 +150,11 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
|
||||||
} while (retval < 0 && errno == EINTR);
|
} while (retval < 0 && errno == EINTR);
|
||||||
|
|
||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
SDL_SetError("sem_timedwait() failed");
|
if (errno == ETIMEDOUT) {
|
||||||
|
retval = SDL_MUTEX_TIMEDOUT;
|
||||||
|
} else {
|
||||||
|
SDL_SetError(strerror(errno));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
end = SDL_GetTicks() + timeout;
|
end = SDL_GetTicks() + timeout;
|
||||||
|
|
|
@ -56,12 +56,13 @@ TestWaitTimeout(void)
|
||||||
Uint32 start_ticks;
|
Uint32 start_ticks;
|
||||||
Uint32 end_ticks;
|
Uint32 end_ticks;
|
||||||
Uint32 duration;
|
Uint32 duration;
|
||||||
|
int retval;
|
||||||
|
|
||||||
sem = SDL_CreateSemaphore(0);
|
sem = SDL_CreateSemaphore(0);
|
||||||
printf("Waiting 2 seconds on semaphore\n");
|
printf("Waiting 2 seconds on semaphore\n");
|
||||||
|
|
||||||
start_ticks = SDL_GetTicks();
|
start_ticks = SDL_GetTicks();
|
||||||
SDL_SemWaitTimeout(sem, 2000);
|
retval = SDL_SemWaitTimeout(sem, 2000);
|
||||||
end_ticks = SDL_GetTicks();
|
end_ticks = SDL_GetTicks();
|
||||||
|
|
||||||
duration = end_ticks - start_ticks;
|
duration = end_ticks - start_ticks;
|
||||||
|
@ -71,6 +72,10 @@ TestWaitTimeout(void)
|
||||||
printf("Wait done.\n");
|
printf("Wait done.\n");
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Wait took %d milliseconds\n", duration);
|
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
|
int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue