Skip to content

Commit

Permalink
Make sure sem_wait didn't return early with EINTR. Fixes Bugzilla #231.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 17, 2006
1 parent 23c4b2f commit f730a6e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/thread/dc/SDL_syssem.c
Expand Up @@ -19,6 +19,9 @@
Sam Lantinga
slouken@libsdl.org
*/

#include <errno.h>

#include "SDL_config.h"

/* An implementation of semaphores using mutexes and condition variables */
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/thread/pthread/SDL_syssem.c
Expand Up @@ -23,6 +23,7 @@

#include <pthread.h>
#include <semaphore.h>
#include <errno.h>

#include "SDL_thread.h"
#include "SDL_timer.h"
Expand Down Expand Up @@ -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");
}
Expand Down
5 changes: 4 additions & 1 deletion src/thread/riscos/SDL_syssem.c
Expand Up @@ -19,6 +19,9 @@
Sam Lantinga
slouken@libsdl.org
*/

#include <errno.h>

#include "SDL_config.h"

/* RISC OS semiphores based on linux code */
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit f730a6e

Please sign in to comment.