src/thread/pthread/SDL_syssem.c
changeset 6219 8e94af244f2c
parent 6138 4c64952a58fb
child 6298 9110462bfc57
     1.1 --- a/src/thread/pthread/SDL_syssem.c	Sat Jan 14 13:21:19 2012 -0500
     1.2 +++ b/src/thread/pthread/SDL_syssem.c	Sun Jan 15 03:34:14 2012 -0500
     1.3 @@ -103,8 +103,12 @@
     1.4  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 @@ -119,6 +123,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 @@ -147,6 +152,15 @@
    1.25      if (retval < 0) {
    1.26          SDL_SetError("sem_timedwait() failed");
    1.27      }
    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  }