test/testsem.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/test/testsem.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/test/testsem.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -14,73 +14,73 @@
     1.4  int alive = 1;
     1.5  
     1.6  int SDLCALL
     1.7 -ThreadFunc (void *data)
     1.8 +ThreadFunc(void *data)
     1.9  {
    1.10      int threadnum = (int) (uintptr_t) data;
    1.11      while (alive) {
    1.12 -        SDL_SemWait (sem);
    1.13 -        fprintf (stderr,
    1.14 -                 "Thread number %d has got the semaphore (value = %d)!\n",
    1.15 -                 threadnum, SDL_SemValue (sem));
    1.16 -        SDL_Delay (200);
    1.17 -        SDL_SemPost (sem);
    1.18 -        fprintf (stderr,
    1.19 -                 "Thread number %d has released the semaphore (value = %d)!\n",
    1.20 -                 threadnum, SDL_SemValue (sem));
    1.21 -        SDL_Delay (1);          /* For the scheduler */
    1.22 +        SDL_SemWait(sem);
    1.23 +        fprintf(stderr,
    1.24 +                "Thread number %d has got the semaphore (value = %d)!\n",
    1.25 +                threadnum, SDL_SemValue(sem));
    1.26 +        SDL_Delay(200);
    1.27 +        SDL_SemPost(sem);
    1.28 +        fprintf(stderr,
    1.29 +                "Thread number %d has released the semaphore (value = %d)!\n",
    1.30 +                threadnum, SDL_SemValue(sem));
    1.31 +        SDL_Delay(1);           /* For the scheduler */
    1.32      }
    1.33 -    printf ("Thread number %d exiting.\n", threadnum);
    1.34 +    printf("Thread number %d exiting.\n", threadnum);
    1.35      return 0;
    1.36  }
    1.37  
    1.38  static void
    1.39 -killed (int sig)
    1.40 +killed(int sig)
    1.41  {
    1.42      alive = 0;
    1.43  }
    1.44  
    1.45  int
    1.46 -main (int argc, char **argv)
    1.47 +main(int argc, char **argv)
    1.48  {
    1.49      SDL_Thread *threads[NUM_THREADS];
    1.50      uintptr_t i;
    1.51      int init_sem;
    1.52  
    1.53      if (argc < 2) {
    1.54 -        fprintf (stderr, "Usage: %s init_value\n", argv[0]);
    1.55 +        fprintf(stderr, "Usage: %s init_value\n", argv[0]);
    1.56          return (1);
    1.57      }
    1.58  
    1.59      /* Load the SDL library */
    1.60 -    if (SDL_Init (0) < 0) {
    1.61 -        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
    1.62 +    if (SDL_Init(0) < 0) {
    1.63 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.64          return (1);
    1.65      }
    1.66 -    signal (SIGTERM, killed);
    1.67 -    signal (SIGINT, killed);
    1.68 +    signal(SIGTERM, killed);
    1.69 +    signal(SIGINT, killed);
    1.70  
    1.71 -    init_sem = atoi (argv[1]);
    1.72 -    sem = SDL_CreateSemaphore (init_sem);
    1.73 +    init_sem = atoi(argv[1]);
    1.74 +    sem = SDL_CreateSemaphore(init_sem);
    1.75  
    1.76 -    printf ("Running %d threads, semaphore value = %d\n", NUM_THREADS,
    1.77 -            init_sem);
    1.78 +    printf("Running %d threads, semaphore value = %d\n", NUM_THREADS,
    1.79 +           init_sem);
    1.80      /* Create all the threads */
    1.81      for (i = 0; i < NUM_THREADS; ++i) {
    1.82 -        threads[i] = SDL_CreateThread (ThreadFunc, (void *) i);
    1.83 +        threads[i] = SDL_CreateThread(ThreadFunc, (void *) i);
    1.84      }
    1.85  
    1.86      /* Wait 10 seconds */
    1.87 -    SDL_Delay (10 * 1000);
    1.88 +    SDL_Delay(10 * 1000);
    1.89  
    1.90      /* Wait for all threads to finish */
    1.91 -    printf ("Waiting for threads to finish\n");
    1.92 +    printf("Waiting for threads to finish\n");
    1.93      alive = 0;
    1.94      for (i = 0; i < NUM_THREADS; ++i) {
    1.95 -        SDL_WaitThread (threads[i], NULL);
    1.96 +        SDL_WaitThread(threads[i], NULL);
    1.97      }
    1.98 -    printf ("Finished waiting for threads\n");
    1.99 +    printf("Finished waiting for threads\n");
   1.100  
   1.101 -    SDL_DestroySemaphore (sem);
   1.102 -    SDL_Quit ();
   1.103 +    SDL_DestroySemaphore(sem);
   1.104 +    SDL_Quit();
   1.105      return (0);
   1.106  }