src/thread/pthread/SDL_syssem.c
branchSDL-1.2
changeset 6218 f114f1434ff6
parent 6137 4720145f848b
child 6297 c787fb1b5699
     1.1 --- a/src/thread/pthread/SDL_syssem.c	Sat Jan 14 02:22:40 2012 -0500
     1.2 +++ b/src/thread/pthread/SDL_syssem.c	Sun Jan 15 03:13:08 2012 -0500
     1.3 @@ -98,8 +98,12 @@
     1.4  int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
     1.5  {
     1.6  	int retval;
     1.7 +#ifdef HAVE_SEM_TIMEDWAIT
     1.8  	struct timeval now;
     1.9  	struct timespec ts_timeout;
    1.10 +#else
    1.11 +	Uint32 end;
    1.12 +#endif
    1.13  
    1.14  	if ( ! sem ) {
    1.15  		SDL_SetError("Passed a NULL semaphore");
    1.16 @@ -114,6 +118,7 @@
    1.17  		return SDL_SemWait(sem);
    1.18  	}
    1.19  
    1.20 +#ifdef HAVE_SEM_TIMEDWAIT
    1.21  	/* Setup the timeout. sem_timedwait doesn't wait for
    1.22  	 * a lapse of time, but until we reach a certain time.
    1.23  	 * This time is now plus the timeout.
    1.24 @@ -141,6 +146,15 @@
    1.25  
    1.26  	if (retval == -1)
    1.27  		SDL_SetError(strerror(errno));
    1.28 +#else
    1.29 +	end = SDL_GetTicks() + timeout;
    1.30 +	while ((retval = SDL_SemTryWait(sem)) == SDL_MUTEX_TIMEDOUT) {
    1.31 +		if ((SDL_GetTicks() - end) >= 0) {
    1.32 +			break;
    1.33 +		}
    1.34 +		SDL_Delay(0);
    1.35 +	}
    1.36 +#endif /* HAVE_SEM_TIMEDWAIT */
    1.37  
    1.38  	return retval;
    1.39  }