test/testlock.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8149 681eb46b8ac4
--- a/test/testlock.c	Mon Aug 12 22:00:21 2013 -0700
+++ b/test/testlock.c	Wed Aug 14 23:30:10 2013 -0700
@@ -40,7 +40,7 @@
 void
 printid(void)
 {
-    printf("Process %lu:  exiting\n", SDL_ThreadID());
+    SDL_Log("Process %lu:  exiting\n", SDL_ThreadID());
 }
 
 void
@@ -55,7 +55,7 @@
 {
     SDL_threadID id = SDL_ThreadID();
     int i;
-    printf("Process %lu:  Cleaning up...\n", id == mainthread ? 0 : id);
+    SDL_Log("Process %lu:  Cleaning up...\n", id == mainthread ? 0 : id);
     doterminate = 1;
     for (i = 0; i < 6; ++i)
         SDL_WaitThread(threads[i], NULL);
@@ -69,23 +69,23 @@
     if (SDL_ThreadID() == mainthread)
         signal(SIGTERM, closemutex);
     while (!doterminate) {
-        printf("Process %lu ready to work\n", SDL_ThreadID());
+        SDL_Log("Process %lu ready to work\n", SDL_ThreadID());
         if (SDL_LockMutex(mutex) < 0) {
-            fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError());
+            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock mutex: %s", SDL_GetError());
             exit(1);
         }
-        printf("Process %lu, working!\n", SDL_ThreadID());
+        SDL_Log("Process %lu, working!\n", SDL_ThreadID());
         SDL_Delay(1 * 1000);
-        printf("Process %lu, done!\n", SDL_ThreadID());
+        SDL_Log("Process %lu, done!\n", SDL_ThreadID());
         if (SDL_UnlockMutex(mutex) < 0) {
-            fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError());
+            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't unlock mutex: %s", SDL_GetError());
             exit(1);
         }
         /* If this sleep isn't done, then threads may starve */
         SDL_Delay(10);
     }
     if (SDL_ThreadID() == mainthread && doterminate) {
-        printf("Process %lu:  raising SIGTERM\n", SDL_ThreadID());
+        SDL_Log("Process %lu:  raising SIGTERM\n", SDL_ThreadID());
         raise(SIGTERM);
     }
     return (0);
@@ -97,26 +97,29 @@
     int i;
     int maxproc = 6;
 
+	/* Enable standard application logging */
+    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
+
     /* Load the SDL library */
     if (SDL_Init(0) < 0) {
-        fprintf(stderr, "%s\n", SDL_GetError());
+        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
         exit(1);
     }
     atexit(SDL_Quit_Wrapper);
 
     if ((mutex = SDL_CreateMutex()) == NULL) {
-        fprintf(stderr, "Couldn't create mutex: %s\n", SDL_GetError());
+        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create mutex: %s\n", SDL_GetError());
         exit(1);
     }
 
     mainthread = SDL_ThreadID();
-    printf("Main thread: %lu\n", mainthread);
+    SDL_Log("Main thread: %lu\n", mainthread);
     atexit(printid);
     for (i = 0; i < maxproc; ++i) {
         char name[64];
         SDL_snprintf(name, sizeof (name), "Worker%d", i);
         if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL)
-            fprintf(stderr, "Couldn't create thread!\n");
+            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n");
     }
     signal(SIGINT, terminate);
     Run(NULL);