Commit f60db175 authored by Ryan C. Gordon's avatar Ryan C. Gordon

Make sure sem_wait didn't return early with EINTR. Fixes Bugzilla #231.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401816
parent 90a334ec
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
Sam Lantinga Sam Lantinga
slouken@libsdl.org slouken@libsdl.org
*/ */
#include <errno.h>
#include "SDL_config.h" #include "SDL_config.h"
/* An implementation of semaphores using mutexes and condition variables */ /* An implementation of semaphores using mutexes and condition variables */
...@@ -135,13 +138,15 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) ...@@ -135,13 +138,15 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
int SDL_SemWait(SDL_sem *sem) int SDL_SemWait(SDL_sem *sem)
{ {
int retval;
if ( ! sem ) { if ( ! sem ) {
SDL_SetError("Passed a NULL semaphore"); SDL_SetError("Passed a NULL semaphore");
return -1; return -1;
} }
sem_wait(&sem->sem); while ( ((retval = sem_wait(&sem->sem)) == -1) && (errno == EINTR) ) {}
return 0; return retval;
} }
Uint32 SDL_SemValue(SDL_sem *sem) Uint32 SDL_SemValue(SDL_sem *sem)
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <pthread.h> #include <pthread.h>
#include <semaphore.h> #include <semaphore.h>
#include <errno.h>
#include "SDL_thread.h" #include "SDL_thread.h"
#include "SDL_timer.h" #include "SDL_timer.h"
...@@ -86,7 +87,7 @@ int SDL_SemWait(SDL_sem *sem) ...@@ -86,7 +87,7 @@ int SDL_SemWait(SDL_sem *sem)
return -1; return -1;
} }
retval = sem_wait(&sem->sem); while ( ((retval = sem_wait(&sem->sem)) == -1) && (errno == EINTR) ) {}
if ( retval < 0 ) { if ( retval < 0 ) {
SDL_SetError("sem_wait() failed"); SDL_SetError("sem_wait() failed");
} }
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
Sam Lantinga Sam Lantinga
slouken@libsdl.org slouken@libsdl.org
*/ */
#include <errno.h>
#include "SDL_config.h" #include "SDL_config.h"
/* RISC OS semiphores based on linux code */ /* RISC OS semiphores based on linux code */
...@@ -132,7 +135,7 @@ int SDL_SemWait(SDL_sem *sem) ...@@ -132,7 +135,7 @@ int SDL_SemWait(SDL_sem *sem)
return -1; return -1;
} }
retval = sem_wait(sem->sem); while ( ((retval = sem_wait(sem->sem)) == -1) && (errno == EINTR) ) {}
if ( retval < 0 ) { if ( retval < 0 ) {
SDL_SetError("sem_wait() failed"); SDL_SetError("sem_wait() failed");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment