From f730a6e3c4a48de503b719db8168d8b495576881 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 17 May 2006 23:42:48 +0000 Subject: [PATCH] Make sure sem_wait didn't return early with EINTR. Fixes Bugzilla #231. --- src/thread/dc/SDL_syssem.c | 9 +++++++-- src/thread/pthread/SDL_syssem.c | 3 ++- src/thread/riscos/SDL_syssem.c | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/thread/dc/SDL_syssem.c b/src/thread/dc/SDL_syssem.c index 51ca8ff08..d9888f7a1 100644 --- a/src/thread/dc/SDL_syssem.c +++ b/src/thread/dc/SDL_syssem.c @@ -19,6 +19,9 @@ Sam Lantinga slouken@libsdl.org */ + +#include + #include "SDL_config.h" /* An implementation of semaphores using mutexes and condition variables */ @@ -135,13 +138,15 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) int SDL_SemWait(SDL_sem *sem) { + int retval; + if ( ! sem ) { SDL_SetError("Passed a NULL semaphore"); return -1; } - sem_wait(&sem->sem); - return 0; + while ( ((retval = sem_wait(&sem->sem)) == -1) && (errno == EINTR) ) {} + return retval; } Uint32 SDL_SemValue(SDL_sem *sem) diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index 50c06613b..c43195ac6 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -23,6 +23,7 @@ #include #include +#include #include "SDL_thread.h" #include "SDL_timer.h" @@ -86,7 +87,7 @@ int SDL_SemWait(SDL_sem *sem) return -1; } - retval = sem_wait(&sem->sem); + while ( ((retval = sem_wait(&sem->sem)) == -1) && (errno == EINTR) ) {} if ( retval < 0 ) { SDL_SetError("sem_wait() failed"); } diff --git a/src/thread/riscos/SDL_syssem.c b/src/thread/riscos/SDL_syssem.c index 0e563883b..775eee355 100644 --- a/src/thread/riscos/SDL_syssem.c +++ b/src/thread/riscos/SDL_syssem.c @@ -19,6 +19,9 @@ Sam Lantinga slouken@libsdl.org */ + +#include + #include "SDL_config.h" /* RISC OS semiphores based on linux code */ @@ -132,7 +135,7 @@ int SDL_SemWait(SDL_sem *sem) return -1; } - retval = sem_wait(sem->sem); + while ( ((retval = sem_wait(sem->sem)) == -1) && (errno == EINTR) ) {} if ( retval < 0 ) { SDL_SetError("sem_wait() failed"); }