test/testsem.c
branchSDL-1.2
changeset 6297 c787fb1b5699
parent 5105 99acf3d856cb
equal deleted inserted replaced
6294:7a2e0f7b30cb 6297:c787fb1b5699
    36 static void TestWaitTimeout(void)
    36 static void TestWaitTimeout(void)
    37 {
    37 {
    38 	Uint32 start_ticks;
    38 	Uint32 start_ticks;
    39 	Uint32 end_ticks;
    39 	Uint32 end_ticks;
    40 	Uint32 duration;
    40 	Uint32 duration;
       
    41 	int retval;
    41 
    42 
    42 	sem = SDL_CreateSemaphore(0);
    43 	sem = SDL_CreateSemaphore(0);
    43 	printf("Waiting 2 seconds on semaphore\n");
    44 	printf("Waiting 2 seconds on semaphore\n");
    44 
    45 
    45 	start_ticks = SDL_GetTicks();
    46 	start_ticks = SDL_GetTicks();
    46 	SDL_SemWaitTimeout(sem, 2000);
    47 	retval = SDL_SemWaitTimeout(sem, 2000);
    47 	end_ticks = SDL_GetTicks();
    48 	end_ticks = SDL_GetTicks();
    48 
    49 
    49 	duration = end_ticks - start_ticks;
    50 	duration = end_ticks - start_ticks;
    50 	
    51 	
    51 	/* Accept a little offset in the effective wait */
    52 	/* Accept a little offset in the effective wait */
    52 	if (duration > 1900 && duration < 2050)
    53 	if (duration > 1900 && duration < 2050)
    53 		printf("Wait done.\n");
    54 		printf("Wait done.\n");
    54 	else
    55 	else
    55 		fprintf(stderr, "Wait took %d milliseconds\n", duration);
    56 		fprintf(stderr, "Wait took %d milliseconds\n", duration);
       
    57 	
       
    58 	/* Check to make sure the return value indicates timed out */
       
    59 	if (retval != SDL_MUTEX_TIMEDOUT) 
       
    60 		fprintf(stderr, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT);
    56 }
    61 }
    57 
    62 
    58 int main(int argc, char **argv)
    63 int main(int argc, char **argv)
    59 {
    64 {
    60 	SDL_Thread *threads[NUM_THREADS];
    65 	SDL_Thread *threads[NUM_THREADS];