test/testlock.c
branchSDL-1.3
changeset 1659 14717b52abc0
parent 1151 be9c9c8f6d53
child 1662 782fd950bd46
child 1895 c121d94672cb
     1.1 --- a/test/testlock.c	Mon May 01 06:58:33 2006 +0000
     1.2 +++ b/test/testlock.c	Wed May 17 08:18:28 2006 +0000
     1.3 @@ -5,7 +5,6 @@
     1.4  
     1.5  #include <signal.h>
     1.6  #include <stdio.h>
     1.7 -#include <stdlib.h>
     1.8  
     1.9  #include "SDL.h"
    1.10  #include "SDL_mutex.h"
    1.11 @@ -14,6 +13,7 @@
    1.12  static SDL_mutex *mutex = NULL;
    1.13  static Uint32 mainthread;
    1.14  static SDL_Thread *threads[6];
    1.15 +static volatile int doterminate = 0;
    1.16  
    1.17  /*
    1.18   * SDL_Quit() shouldn't be used with atexit() directly because
    1.19 @@ -31,8 +31,8 @@
    1.20  	
    1.21  void terminate(int sig)
    1.22  {
    1.23 -	printf("Process %u:  raising SIGTERM\n", SDL_ThreadID());
    1.24 -	raise(SIGTERM);
    1.25 +	signal(SIGINT, terminate);
    1.26 +	doterminate = 1;
    1.27  }
    1.28  void closemutex(int sig)
    1.29  {
    1.30 @@ -44,7 +44,7 @@
    1.31  	SDL_DestroyMutex(mutex);
    1.32  	exit(sig);
    1.33  }
    1.34 -int Run(void *data)
    1.35 +int SDLCALL Run(void *data)
    1.36  {
    1.37  	if ( SDL_ThreadID() == mainthread )
    1.38  		signal(SIGTERM, closemutex);
    1.39 @@ -63,6 +63,10 @@
    1.40  		}
    1.41  		/* If this sleep isn't done, then threads may starve */
    1.42  		SDL_Delay(10);
    1.43 +		if (SDL_ThreadID() == mainthread && doterminate) {
    1.44 +			printf("Process %u:  raising SIGTERM\n", SDL_ThreadID());
    1.45 +			raise(SIGTERM);
    1.46 +		}
    1.47  	}
    1.48  	return(0);
    1.49  }