test/testthread.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8149 681eb46b8ac4
child 8535 e8ee0708ef5c
     1.1 --- a/test/testthread.c	Mon Aug 12 22:00:21 2013 -0700
     1.2 +++ b/test/testthread.c	Wed Aug 14 23:30:10 2013 -0700
     1.3 @@ -34,20 +34,20 @@
     1.4  ThreadFunc(void *data)
     1.5  {
     1.6      SDL_TLSSet(tls, "baby thread", NULL);
     1.7 -    printf("Started thread %s: My thread id is %lu, thread data = %s\n",
     1.8 +    SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
     1.9             (char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
    1.10      while (alive) {
    1.11 -        printf("Thread '%s' is alive!\n", (char *) data);
    1.12 +        SDL_Log("Thread '%s' is alive!\n", (char *) data);
    1.13          SDL_Delay(1 * 1000);
    1.14      }
    1.15 -    printf("Thread '%s' exiting!\n", (char *) data);
    1.16 +    SDL_Log("Thread '%s' exiting!\n", (char *) data);
    1.17      return (0);
    1.18  }
    1.19  
    1.20  static void
    1.21  killed(int sig)
    1.22  {
    1.23 -    printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
    1.24 +    SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n");
    1.25      SDL_Delay(5 * 1000);
    1.26      alive = 0;
    1.27      quit(0);
    1.28 @@ -58,35 +58,38 @@
    1.29  {
    1.30      SDL_Thread *thread;
    1.31  
    1.32 +	/* Enable standard application logging */
    1.33 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.34 +
    1.35      /* Load the SDL library */
    1.36      if (SDL_Init(0) < 0) {
    1.37 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.38 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.39          return (1);
    1.40      }
    1.41  
    1.42      tls = SDL_TLSCreate();
    1.43      SDL_assert(tls);
    1.44      SDL_TLSSet(tls, "main thread", NULL);
    1.45 -    printf("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
    1.46 +    SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
    1.47  
    1.48      alive = 1;
    1.49      thread = SDL_CreateThread(ThreadFunc, "One", "#1");
    1.50      if (thread == NULL) {
    1.51 -        fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    1.52 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
    1.53          quit(1);
    1.54      }
    1.55      SDL_Delay(5 * 1000);
    1.56 -    printf("Waiting for thread #1\n");
    1.57 +    SDL_Log("Waiting for thread #1\n");
    1.58      alive = 0;
    1.59      SDL_WaitThread(thread, NULL);
    1.60  
    1.61 -    printf("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
    1.62 +    SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
    1.63  
    1.64      alive = 1;
    1.65      signal(SIGTERM, killed);
    1.66      thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
    1.67      if (thread == NULL) {
    1.68 -        fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    1.69 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
    1.70          quit(1);
    1.71      }
    1.72      raise(SIGTERM);