Fixed bug 1426 - SDL_SemWaitTimeout returns -1 and sets error instead of SDL_MUTEX_TIMEDOUT on time out
authorSam Lantinga <slouken@libsdl.org>
Mon, 20 Feb 2012 23:51:53 -0500
changeset 62989110462bfc57
parent 6296 b42657486c0d
child 6299 3809b2eee787
Fixed bug 1426 - SDL_SemWaitTimeout returns -1 and sets error instead of SDL_MUTEX_TIMEDOUT on time out

deraj 2012-02-19 19:01:08 PST

Fix to treat ETIMEDOUT as a time out instead of an error (and update the test)
src/thread/pthread/SDL_syssem.c
test/testsem.c
     1.1 --- a/src/thread/pthread/SDL_syssem.c	Mon Feb 20 23:37:57 2012 -0500
     1.2 +++ b/src/thread/pthread/SDL_syssem.c	Mon Feb 20 23:51:53 2012 -0500
     1.3 @@ -150,7 +150,11 @@
     1.4      } while (retval < 0 && errno == EINTR);
     1.5  
     1.6      if (retval < 0) {
     1.7 -        SDL_SetError("sem_timedwait() failed");
     1.8 +        if (errno == ETIMEDOUT) {
     1.9 +            retval = SDL_MUTEX_TIMEDOUT;
    1.10 +        } else {
    1.11 +            SDL_SetError(strerror(errno));
    1.12 +        }
    1.13      }
    1.14  #else
    1.15      end = SDL_GetTicks() + timeout;
     2.1 --- a/test/testsem.c	Mon Feb 20 23:37:57 2012 -0500
     2.2 +++ b/test/testsem.c	Mon Feb 20 23:51:53 2012 -0500
     2.3 @@ -56,12 +56,13 @@
     2.4      Uint32 start_ticks;
     2.5      Uint32 end_ticks;
     2.6      Uint32 duration;
     2.7 +    int retval;
     2.8  
     2.9      sem = SDL_CreateSemaphore(0);
    2.10      printf("Waiting 2 seconds on semaphore\n");
    2.11  
    2.12      start_ticks = SDL_GetTicks();
    2.13 -    SDL_SemWaitTimeout(sem, 2000);
    2.14 +    retval = SDL_SemWaitTimeout(sem, 2000);
    2.15      end_ticks = SDL_GetTicks();
    2.16  
    2.17      duration = end_ticks - start_ticks;
    2.18 @@ -71,6 +72,10 @@
    2.19          printf("Wait done.\n");
    2.20      else
    2.21          fprintf(stderr, "Wait took %d milliseconds\n", duration);
    2.22 +
    2.23 +    /* Check to make sure the return value indicates timed out */
    2.24 +    if (retval != SDL_MUTEX_TIMEDOUT) 
    2.25 +        fprintf(stderr, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT);
    2.26  }
    2.27  
    2.28  int