test/testlock.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8149 681eb46b8ac4
     1.1 --- a/test/testlock.c	Mon Aug 12 22:00:21 2013 -0700
     1.2 +++ b/test/testlock.c	Wed Aug 14 23:30:10 2013 -0700
     1.3 @@ -40,7 +40,7 @@
     1.4  void
     1.5  printid(void)
     1.6  {
     1.7 -    printf("Process %lu:  exiting\n", SDL_ThreadID());
     1.8 +    SDL_Log("Process %lu:  exiting\n", SDL_ThreadID());
     1.9  }
    1.10  
    1.11  void
    1.12 @@ -55,7 +55,7 @@
    1.13  {
    1.14      SDL_threadID id = SDL_ThreadID();
    1.15      int i;
    1.16 -    printf("Process %lu:  Cleaning up...\n", id == mainthread ? 0 : id);
    1.17 +    SDL_Log("Process %lu:  Cleaning up...\n", id == mainthread ? 0 : id);
    1.18      doterminate = 1;
    1.19      for (i = 0; i < 6; ++i)
    1.20          SDL_WaitThread(threads[i], NULL);
    1.21 @@ -69,23 +69,23 @@
    1.22      if (SDL_ThreadID() == mainthread)
    1.23          signal(SIGTERM, closemutex);
    1.24      while (!doterminate) {
    1.25 -        printf("Process %lu ready to work\n", SDL_ThreadID());
    1.26 +        SDL_Log("Process %lu ready to work\n", SDL_ThreadID());
    1.27          if (SDL_LockMutex(mutex) < 0) {
    1.28 -            fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError());
    1.29 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock mutex: %s", SDL_GetError());
    1.30              exit(1);
    1.31          }
    1.32 -        printf("Process %lu, working!\n", SDL_ThreadID());
    1.33 +        SDL_Log("Process %lu, working!\n", SDL_ThreadID());
    1.34          SDL_Delay(1 * 1000);
    1.35 -        printf("Process %lu, done!\n", SDL_ThreadID());
    1.36 +        SDL_Log("Process %lu, done!\n", SDL_ThreadID());
    1.37          if (SDL_UnlockMutex(mutex) < 0) {
    1.38 -            fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError());
    1.39 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't unlock mutex: %s", SDL_GetError());
    1.40              exit(1);
    1.41          }
    1.42          /* If this sleep isn't done, then threads may starve */
    1.43          SDL_Delay(10);
    1.44      }
    1.45      if (SDL_ThreadID() == mainthread && doterminate) {
    1.46 -        printf("Process %lu:  raising SIGTERM\n", SDL_ThreadID());
    1.47 +        SDL_Log("Process %lu:  raising SIGTERM\n", SDL_ThreadID());
    1.48          raise(SIGTERM);
    1.49      }
    1.50      return (0);
    1.51 @@ -97,26 +97,29 @@
    1.52      int i;
    1.53      int maxproc = 6;
    1.54  
    1.55 +	/* Enable standard application logging */
    1.56 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.57 +
    1.58      /* Load the SDL library */
    1.59      if (SDL_Init(0) < 0) {
    1.60 -        fprintf(stderr, "%s\n", SDL_GetError());
    1.61 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
    1.62          exit(1);
    1.63      }
    1.64      atexit(SDL_Quit_Wrapper);
    1.65  
    1.66      if ((mutex = SDL_CreateMutex()) == NULL) {
    1.67 -        fprintf(stderr, "Couldn't create mutex: %s\n", SDL_GetError());
    1.68 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create mutex: %s\n", SDL_GetError());
    1.69          exit(1);
    1.70      }
    1.71  
    1.72      mainthread = SDL_ThreadID();
    1.73 -    printf("Main thread: %lu\n", mainthread);
    1.74 +    SDL_Log("Main thread: %lu\n", mainthread);
    1.75      atexit(printid);
    1.76      for (i = 0; i < maxproc; ++i) {
    1.77          char name[64];
    1.78          SDL_snprintf(name, sizeof (name), "Worker%d", i);
    1.79          if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL)
    1.80 -            fprintf(stderr, "Couldn't create thread!\n");
    1.81 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n");
    1.82      }
    1.83      signal(SIGINT, terminate);
    1.84      Run(NULL);