test/testsem.c
changeset 6298 9110462bfc57
parent 5969 3a041d215edc
child 7191 75360622e65f
equal deleted inserted replaced
6296:b42657486c0d 6298:9110462bfc57
    54 TestWaitTimeout(void)
    54 TestWaitTimeout(void)
    55 {
    55 {
    56     Uint32 start_ticks;
    56     Uint32 start_ticks;
    57     Uint32 end_ticks;
    57     Uint32 end_ticks;
    58     Uint32 duration;
    58     Uint32 duration;
       
    59     int retval;
    59 
    60 
    60     sem = SDL_CreateSemaphore(0);
    61     sem = SDL_CreateSemaphore(0);
    61     printf("Waiting 2 seconds on semaphore\n");
    62     printf("Waiting 2 seconds on semaphore\n");
    62 
    63 
    63     start_ticks = SDL_GetTicks();
    64     start_ticks = SDL_GetTicks();
    64     SDL_SemWaitTimeout(sem, 2000);
    65     retval = SDL_SemWaitTimeout(sem, 2000);
    65     end_ticks = SDL_GetTicks();
    66     end_ticks = SDL_GetTicks();
    66 
    67 
    67     duration = end_ticks - start_ticks;
    68     duration = end_ticks - start_ticks;
    68 
    69 
    69     /* Accept a little offset in the effective wait */
    70     /* Accept a little offset in the effective wait */
    70     if (duration > 1900 && duration < 2050)
    71     if (duration > 1900 && duration < 2050)
    71         printf("Wait done.\n");
    72         printf("Wait done.\n");
    72     else
    73     else
    73         fprintf(stderr, "Wait took %d milliseconds\n", duration);
    74         fprintf(stderr, "Wait took %d milliseconds\n", duration);
       
    75 
       
    76     /* Check to make sure the return value indicates timed out */
       
    77     if (retval != SDL_MUTEX_TIMEDOUT) 
       
    78         fprintf(stderr, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT);
    74 }
    79 }
    75 
    80 
    76 int
    81 int
    77 main(int argc, char **argv)
    82 main(int argc, char **argv)
    78 {
    83 {