test/testlock.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/test/testlock.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/test/testlock.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -20,91 +20,91 @@
     1.4   *  calling conventions may differ...
     1.5   */
     1.6  static void
     1.7 -SDL_Quit_Wrapper (void)
     1.8 +SDL_Quit_Wrapper(void)
     1.9  {
    1.10 -    SDL_Quit ();
    1.11 +    SDL_Quit();
    1.12  }
    1.13  
    1.14  void
    1.15 -printid (void)
    1.16 +printid(void)
    1.17  {
    1.18 -    printf ("Process %u:  exiting\n", SDL_ThreadID ());
    1.19 +    printf("Process %u:  exiting\n", SDL_ThreadID());
    1.20  }
    1.21  
    1.22  void
    1.23 -terminate (int sig)
    1.24 +terminate(int sig)
    1.25  {
    1.26 -    signal (SIGINT, terminate);
    1.27 +    signal(SIGINT, terminate);
    1.28      doterminate = 1;
    1.29  }
    1.30  
    1.31  void
    1.32 -closemutex (int sig)
    1.33 +closemutex(int sig)
    1.34  {
    1.35 -    Uint32 id = SDL_ThreadID ();
    1.36 +    Uint32 id = SDL_ThreadID();
    1.37      int i;
    1.38 -    printf ("Process %u:  Cleaning up...\n", id == mainthread ? 0 : id);
    1.39 +    printf("Process %u:  Cleaning up...\n", id == mainthread ? 0 : id);
    1.40      for (i = 0; i < 6; ++i)
    1.41 -        SDL_KillThread (threads[i]);
    1.42 -    SDL_DestroyMutex (mutex);
    1.43 -    exit (sig);
    1.44 +        SDL_KillThread(threads[i]);
    1.45 +    SDL_DestroyMutex(mutex);
    1.46 +    exit(sig);
    1.47  }
    1.48  
    1.49  int SDLCALL
    1.50 -Run (void *data)
    1.51 +Run(void *data)
    1.52  {
    1.53 -    if (SDL_ThreadID () == mainthread)
    1.54 -        signal (SIGTERM, closemutex);
    1.55 +    if (SDL_ThreadID() == mainthread)
    1.56 +        signal(SIGTERM, closemutex);
    1.57      while (1) {
    1.58 -        printf ("Process %u ready to work\n", SDL_ThreadID ());
    1.59 -        if (SDL_mutexP (mutex) < 0) {
    1.60 -            fprintf (stderr, "Couldn't lock mutex: %s", SDL_GetError ());
    1.61 -            exit (1);
    1.62 +        printf("Process %u ready to work\n", SDL_ThreadID());
    1.63 +        if (SDL_mutexP(mutex) < 0) {
    1.64 +            fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError());
    1.65 +            exit(1);
    1.66          }
    1.67 -        printf ("Process %u, working!\n", SDL_ThreadID ());
    1.68 -        SDL_Delay (1 * 1000);
    1.69 -        printf ("Process %u, done!\n", SDL_ThreadID ());
    1.70 -        if (SDL_mutexV (mutex) < 0) {
    1.71 -            fprintf (stderr, "Couldn't unlock mutex: %s", SDL_GetError ());
    1.72 -            exit (1);
    1.73 +        printf("Process %u, working!\n", SDL_ThreadID());
    1.74 +        SDL_Delay(1 * 1000);
    1.75 +        printf("Process %u, done!\n", SDL_ThreadID());
    1.76 +        if (SDL_mutexV(mutex) < 0) {
    1.77 +            fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError());
    1.78 +            exit(1);
    1.79          }
    1.80          /* If this sleep isn't done, then threads may starve */
    1.81 -        SDL_Delay (10);
    1.82 -        if (SDL_ThreadID () == mainthread && doterminate) {
    1.83 -            printf ("Process %u:  raising SIGTERM\n", SDL_ThreadID ());
    1.84 -            raise (SIGTERM);
    1.85 +        SDL_Delay(10);
    1.86 +        if (SDL_ThreadID() == mainthread && doterminate) {
    1.87 +            printf("Process %u:  raising SIGTERM\n", SDL_ThreadID());
    1.88 +            raise(SIGTERM);
    1.89          }
    1.90      }
    1.91      return (0);
    1.92  }
    1.93  
    1.94  int
    1.95 -main (int argc, char *argv[])
    1.96 +main(int argc, char *argv[])
    1.97  {
    1.98      int i;
    1.99      int maxproc = 6;
   1.100  
   1.101      /* Load the SDL library */
   1.102 -    if (SDL_Init (0) < 0) {
   1.103 -        fprintf (stderr, "%s\n", SDL_GetError ());
   1.104 -        exit (1);
   1.105 +    if (SDL_Init(0) < 0) {
   1.106 +        fprintf(stderr, "%s\n", SDL_GetError());
   1.107 +        exit(1);
   1.108      }
   1.109 -    atexit (SDL_Quit_Wrapper);
   1.110 +    atexit(SDL_Quit_Wrapper);
   1.111  
   1.112 -    if ((mutex = SDL_CreateMutex ()) == NULL) {
   1.113 -        fprintf (stderr, "Couldn't create mutex: %s\n", SDL_GetError ());
   1.114 -        exit (1);
   1.115 +    if ((mutex = SDL_CreateMutex()) == NULL) {
   1.116 +        fprintf(stderr, "Couldn't create mutex: %s\n", SDL_GetError());
   1.117 +        exit(1);
   1.118      }
   1.119  
   1.120 -    mainthread = SDL_ThreadID ();
   1.121 -    printf ("Main thread: %u\n", mainthread);
   1.122 -    atexit (printid);
   1.123 +    mainthread = SDL_ThreadID();
   1.124 +    printf("Main thread: %u\n", mainthread);
   1.125 +    atexit(printid);
   1.126      for (i = 0; i < maxproc; ++i) {
   1.127 -        if ((threads[i] = SDL_CreateThread (Run, NULL)) == NULL)
   1.128 -            fprintf (stderr, "Couldn't create thread!\n");
   1.129 +        if ((threads[i] = SDL_CreateThread(Run, NULL)) == NULL)
   1.130 +            fprintf(stderr, "Couldn't create thread!\n");
   1.131      }
   1.132 -    signal (SIGINT, terminate);
   1.133 -    Run (NULL);
   1.134 +    signal(SIGINT, terminate);
   1.135 +    Run(NULL);
   1.136  
   1.137      return (0);                 /* Never reached */
   1.138  }