test/testsem.c
branchSDL-1.2
changeset 5105 99acf3d856cb
parent 1769 290b5baf2fca
child 6297 c787fb1b5699
equal deleted inserted replaced
5101:3500563bb2f8 5105:99acf3d856cb
    29 }
    29 }
    30 
    30 
    31 static void killed(int sig)
    31 static void killed(int sig)
    32 {
    32 {
    33 	alive = 0;
    33 	alive = 0;
       
    34 }
       
    35 
       
    36 static void TestWaitTimeout(void)
       
    37 {
       
    38 	Uint32 start_ticks;
       
    39 	Uint32 end_ticks;
       
    40 	Uint32 duration;
       
    41 
       
    42 	sem = SDL_CreateSemaphore(0);
       
    43 	printf("Waiting 2 seconds on semaphore\n");
       
    44 
       
    45 	start_ticks = SDL_GetTicks();
       
    46 	SDL_SemWaitTimeout(sem, 2000);
       
    47 	end_ticks = SDL_GetTicks();
       
    48 
       
    49 	duration = end_ticks - start_ticks;
       
    50 	
       
    51 	/* Accept a little offset in the effective wait */
       
    52 	if (duration > 1900 && duration < 2050)
       
    53 		printf("Wait done.\n");
       
    54 	else
       
    55 		fprintf(stderr, "Wait took %d milliseconds\n", duration);
    34 }
    56 }
    35 
    57 
    36 int main(int argc, char **argv)
    58 int main(int argc, char **argv)
    37 {
    59 {
    38 	SDL_Thread *threads[NUM_THREADS];
    60 	SDL_Thread *threads[NUM_THREADS];
    71 		SDL_WaitThread(threads[i], NULL);
    93 		SDL_WaitThread(threads[i], NULL);
    72 	}
    94 	}
    73 	printf("Finished waiting for threads\n");
    95 	printf("Finished waiting for threads\n");
    74 
    96 
    75 	SDL_DestroySemaphore(sem);
    97 	SDL_DestroySemaphore(sem);
       
    98 
       
    99 	TestWaitTimeout();
       
   100 
    76 	SDL_Quit();
   101 	SDL_Quit();
    77 	return(0);
   102 	return(0);
    78 }
   103 }