test/testlock.c
changeset 10003 d91a2c45825e
parent 9998 f67cf37e9cd4
child 10737 3406a0f8b041
     1.1 --- a/test/testlock.c	Sat Jan 02 12:17:33 2016 -0800
     1.2 +++ b/test/testlock.c	Sun Jan 03 06:50:50 2016 -0500
     1.3 @@ -23,7 +23,7 @@
     1.4  static SDL_mutex *mutex = NULL;
     1.5  static SDL_threadID mainthread;
     1.6  static SDL_Thread *threads[6];
     1.7 -static volatile int doterminate = 0;
     1.8 +static SDL_atomic_t doterminate;
     1.9  
    1.10  /*
    1.11   * SDL_Quit() shouldn't be used with atexit() directly because
    1.12 @@ -45,7 +45,7 @@
    1.13  terminate(int sig)
    1.14  {
    1.15      signal(SIGINT, terminate);
    1.16 -    doterminate = 1;
    1.17 +    SDL_AtomicSet(&doterminate, 1);
    1.18  }
    1.19  
    1.20  void
    1.21 @@ -54,7 +54,7 @@
    1.22      SDL_threadID id = SDL_ThreadID();
    1.23      int i;
    1.24      SDL_Log("Process %lu:  Cleaning up...\n", id == mainthread ? 0 : id);
    1.25 -    doterminate = 1;
    1.26 +    SDL_AtomicSet(&doterminate, 1);
    1.27      for (i = 0; i < 6; ++i)
    1.28          SDL_WaitThread(threads[i], NULL);
    1.29      SDL_DestroyMutex(mutex);
    1.30 @@ -66,7 +66,7 @@
    1.31  {
    1.32      if (SDL_ThreadID() == mainthread)
    1.33          signal(SIGTERM, closemutex);
    1.34 -    while (!doterminate) {
    1.35 +    while (!SDL_AtomicGet(&doterminate)) {
    1.36          SDL_Log("Process %lu ready to work\n", SDL_ThreadID());
    1.37          if (SDL_LockMutex(mutex) < 0) {
    1.38              SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock mutex: %s", SDL_GetError());
    1.39 @@ -82,7 +82,7 @@
    1.40          /* If this sleep isn't done, then threads may starve */
    1.41          SDL_Delay(10);
    1.42      }
    1.43 -    if (SDL_ThreadID() == mainthread && doterminate) {
    1.44 +    if (SDL_ThreadID() == mainthread && SDL_AtomicGet(&doterminate)) {
    1.45          SDL_Log("Process %lu:  raising SIGTERM\n", SDL_ThreadID());
    1.46          raise(SIGTERM);
    1.47      }
    1.48 @@ -105,6 +105,8 @@
    1.49      }
    1.50      atexit(SDL_Quit_Wrapper);
    1.51  
    1.52 +    SDL_AtomicSet(&doterminate, 0);
    1.53 +
    1.54      if ((mutex = SDL_CreateMutex()) == NULL) {
    1.55          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create mutex: %s\n", SDL_GetError());
    1.56          exit(1);