Make sure sem_wait didn't return early with EINTR. Fixes Bugzilla #231.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 17 May 2006 23:42:48 +0000
changeset 1851536b0704b7d8
parent 1850 d5d3a6fe05a1
child 1852 eb2d5480ae95
Make sure sem_wait didn't return early with EINTR. Fixes Bugzilla #231.
src/thread/dc/SDL_syssem.c
src/thread/pthread/SDL_syssem.c
src/thread/riscos/SDL_syssem.c
     1.1 --- a/src/thread/dc/SDL_syssem.c	Wed May 17 18:57:04 2006 +0000
     1.2 +++ b/src/thread/dc/SDL_syssem.c	Wed May 17 23:42:48 2006 +0000
     1.3 @@ -19,6 +19,9 @@
     1.4      Sam Lantinga
     1.5      slouken@libsdl.org
     1.6  */
     1.7 +
     1.8 +#include <errno.h>
     1.9 +
    1.10  #include "SDL_config.h"
    1.11  
    1.12  /* An implementation of semaphores using mutexes and condition variables */
    1.13 @@ -135,13 +138,15 @@
    1.14  
    1.15  int SDL_SemWait(SDL_sem *sem)
    1.16  {
    1.17 +	int retval;
    1.18 +
    1.19  	if ( ! sem ) {
    1.20  		SDL_SetError("Passed a NULL semaphore");
    1.21  		return -1;
    1.22  	}
    1.23  
    1.24 -	sem_wait(&sem->sem);
    1.25 -	return 0;
    1.26 +	while ( ((retval = sem_wait(&sem->sem)) == -1) && (errno == EINTR) ) {}
    1.27 +	return retval;
    1.28  }
    1.29  
    1.30  Uint32 SDL_SemValue(SDL_sem *sem)
     2.1 --- a/src/thread/pthread/SDL_syssem.c	Wed May 17 18:57:04 2006 +0000
     2.2 +++ b/src/thread/pthread/SDL_syssem.c	Wed May 17 23:42:48 2006 +0000
     2.3 @@ -23,6 +23,7 @@
     2.4  
     2.5  #include <pthread.h>
     2.6  #include <semaphore.h>
     2.7 +#include <errno.h>
     2.8  
     2.9  #include "SDL_thread.h"
    2.10  #include "SDL_timer.h"
    2.11 @@ -86,7 +87,7 @@
    2.12  		return -1;
    2.13  	}
    2.14  
    2.15 -	retval = sem_wait(&sem->sem);
    2.16 +	while ( ((retval = sem_wait(&sem->sem)) == -1) && (errno == EINTR) ) {}
    2.17  	if ( retval < 0 ) {
    2.18  		SDL_SetError("sem_wait() failed");
    2.19  	}
     3.1 --- a/src/thread/riscos/SDL_syssem.c	Wed May 17 18:57:04 2006 +0000
     3.2 +++ b/src/thread/riscos/SDL_syssem.c	Wed May 17 23:42:48 2006 +0000
     3.3 @@ -19,6 +19,9 @@
     3.4      Sam Lantinga
     3.5      slouken@libsdl.org
     3.6  */
     3.7 +
     3.8 +#include <errno.h>
     3.9 +
    3.10  #include "SDL_config.h"
    3.11  
    3.12  /* RISC OS semiphores based on linux code */
    3.13 @@ -132,7 +135,7 @@
    3.14  		return -1;
    3.15  	}
    3.16  
    3.17 -	retval = sem_wait(sem->sem);
    3.18 +	while ( ((retval = sem_wait(sem->sem)) == -1) && (errno == EINTR) ) {}
    3.19  	if ( retval < 0 ) {
    3.20  		SDL_SetError("sem_wait() failed");
    3.21  	}