test/testsem.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8149 681eb46b8ac4
     1.1 --- a/test/testsem.c	Mon Aug 12 22:00:21 2013 -0700
     1.2 +++ b/test/testsem.c	Wed Aug 14 23:30:10 2013 -0700
     1.3 @@ -30,17 +30,15 @@
     1.4      int threadnum = (int) (uintptr_t) data;
     1.5      while (alive) {
     1.6          SDL_SemWait(sem);
     1.7 -        fprintf(stderr,
     1.8 -                "Thread number %d has got the semaphore (value = %d)!\n",
     1.9 +        SDL_Log("Thread number %d has got the semaphore (value = %d)!\n",
    1.10                  threadnum, SDL_SemValue(sem));
    1.11          SDL_Delay(200);
    1.12          SDL_SemPost(sem);
    1.13 -        fprintf(stderr,
    1.14 -                "Thread number %d has released the semaphore (value = %d)!\n",
    1.15 +        SDL_Log("Thread number %d has released the semaphore (value = %d)!\n",
    1.16                  threadnum, SDL_SemValue(sem));
    1.17          SDL_Delay(1);           /* For the scheduler */
    1.18      }
    1.19 -    printf("Thread number %d exiting.\n", threadnum);
    1.20 +    SDL_Log("Thread number %d exiting.\n", threadnum);
    1.21      return 0;
    1.22  }
    1.23  
    1.24 @@ -59,7 +57,7 @@
    1.25      int retval;
    1.26  
    1.27      sem = SDL_CreateSemaphore(0);
    1.28 -    printf("Waiting 2 seconds on semaphore\n");
    1.29 +    SDL_Log("Waiting 2 seconds on semaphore\n");
    1.30  
    1.31      start_ticks = SDL_GetTicks();
    1.32      retval = SDL_SemWaitTimeout(sem, 2000);
    1.33 @@ -69,13 +67,13 @@
    1.34  
    1.35      /* Accept a little offset in the effective wait */
    1.36      if (duration > 1900 && duration < 2050)
    1.37 -        printf("Wait done.\n");
    1.38 +        SDL_Log("Wait done.\n");
    1.39      else
    1.40 -        fprintf(stderr, "Wait took %d milliseconds\n", duration);
    1.41 +        SDL_Log("Wait took %d milliseconds\n", duration);
    1.42  
    1.43      /* Check to make sure the return value indicates timed out */
    1.44      if (retval != SDL_MUTEX_TIMEDOUT)
    1.45 -        fprintf(stderr, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT);
    1.46 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT);
    1.47  }
    1.48  
    1.49  int
    1.50 @@ -85,14 +83,17 @@
    1.51      uintptr_t i;
    1.52      int init_sem;
    1.53  
    1.54 +	/* Enable standard application logging */
    1.55 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.56 +
    1.57      if (argc < 2) {
    1.58 -        fprintf(stderr, "Usage: %s init_value\n", argv[0]);
    1.59 +        SDL_Log("Usage: %s init_value\n", argv[0]);
    1.60          return (1);
    1.61      }
    1.62  
    1.63      /* Load the SDL library */
    1.64      if (SDL_Init(0) < 0) {
    1.65 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.66 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.67          return (1);
    1.68      }
    1.69      signal(SIGTERM, killed);
    1.70 @@ -101,7 +102,7 @@
    1.71      init_sem = atoi(argv[1]);
    1.72      sem = SDL_CreateSemaphore(init_sem);
    1.73  
    1.74 -    printf("Running %d threads, semaphore value = %d\n", NUM_THREADS,
    1.75 +    SDL_Log("Running %d threads, semaphore value = %d\n", NUM_THREADS,
    1.76             init_sem);
    1.77      /* Create all the threads */
    1.78      for (i = 0; i < NUM_THREADS; ++i) {
    1.79 @@ -114,12 +115,12 @@
    1.80      SDL_Delay(10 * 1000);
    1.81  
    1.82      /* Wait for all threads to finish */
    1.83 -    printf("Waiting for threads to finish\n");
    1.84 +    SDL_Log("Waiting for threads to finish\n");
    1.85      alive = 0;
    1.86      for (i = 0; i < NUM_THREADS; ++i) {
    1.87          SDL_WaitThread(threads[i], NULL);
    1.88      }
    1.89 -    printf("Finished waiting for threads\n");
    1.90 +    SDL_Log("Finished waiting for threads\n");
    1.91  
    1.92      SDL_DestroySemaphore(sem);
    1.93