test/testsem.c
changeset 5106 d547877e355e
parent 1895 c121d94672cb
child 5535 96594ac5fd1a
equal deleted inserted replaced
5104:5fe0330b0fd6 5106:d547877e355e
    35 
    35 
    36 static void
    36 static void
    37 killed(int sig)
    37 killed(int sig)
    38 {
    38 {
    39     alive = 0;
    39     alive = 0;
       
    40 }
       
    41 
       
    42 static void
       
    43 TestWaitTimeout(void)
       
    44 {
       
    45     Uint32 start_ticks;
       
    46     Uint32 end_ticks;
       
    47     Uint32 duration;
       
    48 
       
    49     sem = SDL_CreateSemaphore(0);
       
    50     printf("Waiting 2 seconds on semaphore\n");
       
    51 
       
    52     start_ticks = SDL_GetTicks();
       
    53     SDL_SemWaitTimeout(sem, 2000);
       
    54     end_ticks = SDL_GetTicks();
       
    55 
       
    56     duration = end_ticks - start_ticks;
       
    57 
       
    58     /* Accept a little offset in the effective wait */
       
    59     if (duration > 1900 && duration < 2050)
       
    60         printf("Wait done.\n");
       
    61     else
       
    62         fprintf(stderr, "Wait took %d milliseconds\n", duration);
    40 }
    63 }
    41 
    64 
    42 int
    65 int
    43 main(int argc, char **argv)
    66 main(int argc, char **argv)
    44 {
    67 {
    79         SDL_WaitThread(threads[i], NULL);
   102         SDL_WaitThread(threads[i], NULL);
    80     }
   103     }
    81     printf("Finished waiting for threads\n");
   104     printf("Finished waiting for threads\n");
    82 
   105 
    83     SDL_DestroySemaphore(sem);
   106     SDL_DestroySemaphore(sem);
       
   107 
       
   108     TestWaitTimeout();
       
   109 
    84     SDL_Quit();
   110     SDL_Quit();
    85     return (0);
   111     return (0);
    86 }
   112 }