test/testsem.c
branchSDL-1.2
changeset 5105 99acf3d856cb
parent 1769 290b5baf2fca
child 6297 c787fb1b5699
     1.1 --- a/test/testsem.c	Wed Jan 26 12:26:27 2011 -0800
     1.2 +++ b/test/testsem.c	Thu Jan 27 00:33:26 2011 -0800
     1.3 @@ -33,6 +33,28 @@
     1.4  	alive = 0;
     1.5  }
     1.6  
     1.7 +static void TestWaitTimeout(void)
     1.8 +{
     1.9 +	Uint32 start_ticks;
    1.10 +	Uint32 end_ticks;
    1.11 +	Uint32 duration;
    1.12 +
    1.13 +	sem = SDL_CreateSemaphore(0);
    1.14 +	printf("Waiting 2 seconds on semaphore\n");
    1.15 +
    1.16 +	start_ticks = SDL_GetTicks();
    1.17 +	SDL_SemWaitTimeout(sem, 2000);
    1.18 +	end_ticks = SDL_GetTicks();
    1.19 +
    1.20 +	duration = end_ticks - start_ticks;
    1.21 +	
    1.22 +	/* Accept a little offset in the effective wait */
    1.23 +	if (duration > 1900 && duration < 2050)
    1.24 +		printf("Wait done.\n");
    1.25 +	else
    1.26 +		fprintf(stderr, "Wait took %d milliseconds\n", duration);
    1.27 +}
    1.28 +
    1.29  int main(int argc, char **argv)
    1.30  {
    1.31  	SDL_Thread *threads[NUM_THREADS];
    1.32 @@ -73,6 +95,9 @@
    1.33  	printf("Finished waiting for threads\n");
    1.34  
    1.35  	SDL_DestroySemaphore(sem);
    1.36 +
    1.37 +	TestWaitTimeout();
    1.38 +
    1.39  	SDL_Quit();
    1.40  	return(0);
    1.41  }