src/thread/SDL_thread.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/src/thread/SDL_thread.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/thread/SDL_thread.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -39,12 +39,12 @@
     1.4  static SDL_mutex *thread_lock = NULL;
     1.5  
     1.6  int
     1.7 -SDL_ThreadsInit (void)
     1.8 +SDL_ThreadsInit(void)
     1.9  {
    1.10      int retval;
    1.11  
    1.12      retval = 0;
    1.13 -    thread_lock = SDL_CreateMutex ();
    1.14 +    thread_lock = SDL_CreateMutex();
    1.15      if (thread_lock == NULL) {
    1.16          retval = -1;
    1.17      }
    1.18 @@ -57,20 +57,20 @@
    1.19     they will no longer have access to any per-thread data.
    1.20   */
    1.21  void
    1.22 -SDL_ThreadsQuit (void)
    1.23 +SDL_ThreadsQuit(void)
    1.24  {
    1.25      SDL_mutex *mutex;
    1.26  
    1.27      mutex = thread_lock;
    1.28      thread_lock = NULL;
    1.29      if (mutex != NULL) {
    1.30 -        SDL_DestroyMutex (mutex);
    1.31 +        SDL_DestroyMutex(mutex);
    1.32      }
    1.33  }
    1.34  
    1.35  /* Routines for manipulating the thread list */
    1.36  static void
    1.37 -SDL_AddThread (SDL_Thread * thread)
    1.38 +SDL_AddThread(SDL_Thread * thread)
    1.39  {
    1.40      /* WARNING:
    1.41         If the very first threads are created simultaneously, then
    1.42 @@ -79,25 +79,25 @@
    1.43         is only one thread running the first time this is called.
    1.44       */
    1.45      if (!thread_lock) {
    1.46 -        if (SDL_ThreadsInit () < 0) {
    1.47 +        if (SDL_ThreadsInit() < 0) {
    1.48              return;
    1.49          }
    1.50      }
    1.51 -    SDL_mutexP (thread_lock);
    1.52 +    SDL_mutexP(thread_lock);
    1.53  
    1.54      /* Expand the list of threads, if necessary */
    1.55  #ifdef DEBUG_THREADS
    1.56 -    printf ("Adding thread (%d already - %d max)\n",
    1.57 -            SDL_numthreads, SDL_maxthreads);
    1.58 +    printf("Adding thread (%d already - %d max)\n",
    1.59 +           SDL_numthreads, SDL_maxthreads);
    1.60  #endif
    1.61      if (SDL_numthreads == SDL_maxthreads) {
    1.62          SDL_Thread **threads;
    1.63 -        threads = (SDL_Thread **) SDL_realloc (SDL_Threads,
    1.64 -                                               (SDL_maxthreads +
    1.65 -                                                ARRAY_CHUNKSIZE) *
    1.66 -                                               (sizeof *threads));
    1.67 +        threads = (SDL_Thread **) SDL_realloc(SDL_Threads,
    1.68 +                                              (SDL_maxthreads +
    1.69 +                                               ARRAY_CHUNKSIZE) *
    1.70 +                                              (sizeof *threads));
    1.71          if (threads == NULL) {
    1.72 -            SDL_OutOfMemory ();
    1.73 +            SDL_OutOfMemory();
    1.74              goto done;
    1.75          }
    1.76          SDL_maxthreads += ARRAY_CHUNKSIZE;
    1.77 @@ -105,18 +105,18 @@
    1.78      }
    1.79      SDL_Threads[SDL_numthreads++] = thread;
    1.80    done:
    1.81 -    SDL_mutexV (thread_lock);
    1.82 +    SDL_mutexV(thread_lock);
    1.83  }
    1.84  
    1.85  static void
    1.86 -SDL_DelThread (SDL_Thread * thread)
    1.87 +SDL_DelThread(SDL_Thread * thread)
    1.88  {
    1.89      int i;
    1.90  
    1.91      if (!thread_lock) {
    1.92          return;
    1.93      }
    1.94 -    SDL_mutexP (thread_lock);
    1.95 +    SDL_mutexP(thread_lock);
    1.96      for (i = 0; i < SDL_numthreads; ++i) {
    1.97          if (thread == SDL_Threads[i]) {
    1.98              break;
    1.99 @@ -130,18 +130,18 @@
   1.100              }
   1.101          } else {
   1.102              SDL_maxthreads = 0;
   1.103 -            SDL_free (SDL_Threads);
   1.104 +            SDL_free(SDL_Threads);
   1.105              SDL_Threads = NULL;
   1.106          }
   1.107  #ifdef DEBUG_THREADS
   1.108 -        printf ("Deleting thread (%d left - %d max)\n",
   1.109 -                SDL_numthreads, SDL_maxthreads);
   1.110 +        printf("Deleting thread (%d left - %d max)\n",
   1.111 +               SDL_numthreads, SDL_maxthreads);
   1.112  #endif
   1.113      }
   1.114 -    SDL_mutexV (thread_lock);
   1.115 +    SDL_mutexV(thread_lock);
   1.116  
   1.117      if (SDL_Threads == NULL) {
   1.118 -        SDL_ThreadsQuit ();
   1.119 +        SDL_ThreadsQuit();
   1.120      }
   1.121  }
   1.122  
   1.123 @@ -150,7 +150,7 @@
   1.124  
   1.125  /* Routine to get the thread-specific error variable */
   1.126  SDL_error *
   1.127 -SDL_GetErrBuf (void)
   1.128 +SDL_GetErrBuf(void)
   1.129  {
   1.130      SDL_error *errbuf;
   1.131  
   1.132 @@ -159,15 +159,15 @@
   1.133          int i;
   1.134          Uint32 this_thread;
   1.135  
   1.136 -        this_thread = SDL_ThreadID ();
   1.137 -        SDL_mutexP (thread_lock);
   1.138 +        this_thread = SDL_ThreadID();
   1.139 +        SDL_mutexP(thread_lock);
   1.140          for (i = 0; i < SDL_numthreads; ++i) {
   1.141              if (this_thread == SDL_Threads[i]->threadid) {
   1.142                  errbuf = &SDL_Threads[i]->errbuf;
   1.143                  break;
   1.144              }
   1.145          }
   1.146 -        SDL_mutexV (thread_lock);
   1.147 +        SDL_mutexV(thread_lock);
   1.148      }
   1.149      return (errbuf);
   1.150  }
   1.151 @@ -183,7 +183,7 @@
   1.152  } thread_args;
   1.153  
   1.154  void
   1.155 -SDL_RunThread (void *data)
   1.156 +SDL_RunThread(void *data)
   1.157  {
   1.158      thread_args *args;
   1.159      int (SDLCALL * userfunc) (void *);
   1.160 @@ -193,11 +193,11 @@
   1.161      /* Perform any system-dependent setup
   1.162         - this function cannot fail, and cannot use SDL_SetError()
   1.163       */
   1.164 -    SDL_SYS_SetupThread ();
   1.165 +    SDL_SYS_SetupThread();
   1.166  
   1.167      /* Get the thread id */
   1.168      args = (thread_args *) data;
   1.169 -    args->info->threadid = SDL_ThreadID ();
   1.170 +    args->info->threadid = SDL_ThreadID();
   1.171  
   1.172      /* Figure out what function to run */
   1.173      userfunc = args->func;
   1.174 @@ -205,21 +205,21 @@
   1.175      statusloc = &args->info->status;
   1.176  
   1.177      /* Wake up the parent thread */
   1.178 -    SDL_SemPost (args->wait);
   1.179 +    SDL_SemPost(args->wait);
   1.180  
   1.181      /* Run the function */
   1.182 -    *statusloc = userfunc (userdata);
   1.183 +    *statusloc = userfunc(userdata);
   1.184  }
   1.185  
   1.186  #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
   1.187  #undef SDL_CreateThread
   1.188  DECLSPEC SDL_Thread *SDLCALL
   1.189 -SDL_CreateThread (int (SDLCALL * fn) (void *), void *data,
   1.190 -                  pfnSDL_CurrentBeginThread pfnBeginThread,
   1.191 -                  pfnSDL_CurrentEndThread pfnEndThread)
   1.192 +SDL_CreateThread(int (SDLCALL * fn) (void *), void *data,
   1.193 +                 pfnSDL_CurrentBeginThread pfnBeginThread,
   1.194 +                 pfnSDL_CurrentEndThread pfnEndThread)
   1.195  #else
   1.196  DECLSPEC SDL_Thread *SDLCALL
   1.197 -SDL_CreateThread (int (SDLCALL * fn) (void *), void *data)
   1.198 +SDL_CreateThread(int (SDLCALL * fn) (void *), void *data)
   1.199  #endif
   1.200  {
   1.201      SDL_Thread *thread;
   1.202 @@ -227,88 +227,88 @@
   1.203      int ret;
   1.204  
   1.205      /* Allocate memory for the thread info structure */
   1.206 -    thread = (SDL_Thread *) SDL_malloc (sizeof (*thread));
   1.207 +    thread = (SDL_Thread *) SDL_malloc(sizeof(*thread));
   1.208      if (thread == NULL) {
   1.209 -        SDL_OutOfMemory ();
   1.210 +        SDL_OutOfMemory();
   1.211          return (NULL);
   1.212      }
   1.213 -    SDL_memset (thread, 0, (sizeof *thread));
   1.214 +    SDL_memset(thread, 0, (sizeof *thread));
   1.215      thread->status = -1;
   1.216  
   1.217      /* Set up the arguments for the thread */
   1.218 -    args = (thread_args *) SDL_malloc (sizeof (*args));
   1.219 +    args = (thread_args *) SDL_malloc(sizeof(*args));
   1.220      if (args == NULL) {
   1.221 -        SDL_OutOfMemory ();
   1.222 -        SDL_free (thread);
   1.223 +        SDL_OutOfMemory();
   1.224 +        SDL_free(thread);
   1.225          return (NULL);
   1.226      }
   1.227      args->func = fn;
   1.228      args->data = data;
   1.229      args->info = thread;
   1.230 -    args->wait = SDL_CreateSemaphore (0);
   1.231 +    args->wait = SDL_CreateSemaphore(0);
   1.232      if (args->wait == NULL) {
   1.233 -        SDL_free (thread);
   1.234 -        SDL_free (args);
   1.235 +        SDL_free(thread);
   1.236 +        SDL_free(args);
   1.237          return (NULL);
   1.238      }
   1.239  
   1.240      /* Add the thread to the list of available threads */
   1.241 -    SDL_AddThread (thread);
   1.242 +    SDL_AddThread(thread);
   1.243  
   1.244      /* Create the thread and go! */
   1.245  #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
   1.246 -    ret = SDL_SYS_CreateThread (thread, args, pfnBeginThread, pfnEndThread);
   1.247 +    ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread);
   1.248  #else
   1.249 -    ret = SDL_SYS_CreateThread (thread, args);
   1.250 +    ret = SDL_SYS_CreateThread(thread, args);
   1.251  #endif
   1.252      if (ret >= 0) {
   1.253          /* Wait for the thread function to use arguments */
   1.254 -        SDL_SemWait (args->wait);
   1.255 +        SDL_SemWait(args->wait);
   1.256      } else {
   1.257          /* Oops, failed.  Gotta free everything */
   1.258 -        SDL_DelThread (thread);
   1.259 -        SDL_free (thread);
   1.260 +        SDL_DelThread(thread);
   1.261 +        SDL_free(thread);
   1.262          thread = NULL;
   1.263      }
   1.264 -    SDL_DestroySemaphore (args->wait);
   1.265 -    SDL_free (args);
   1.266 +    SDL_DestroySemaphore(args->wait);
   1.267 +    SDL_free(args);
   1.268  
   1.269      /* Everything is running now */
   1.270      return (thread);
   1.271  }
   1.272  
   1.273  void
   1.274 -SDL_WaitThread (SDL_Thread * thread, int *status)
   1.275 +SDL_WaitThread(SDL_Thread * thread, int *status)
   1.276  {
   1.277      if (thread) {
   1.278 -        SDL_SYS_WaitThread (thread);
   1.279 +        SDL_SYS_WaitThread(thread);
   1.280          if (status) {
   1.281              *status = thread->status;
   1.282          }
   1.283 -        SDL_DelThread (thread);
   1.284 -        SDL_free (thread);
   1.285 +        SDL_DelThread(thread);
   1.286 +        SDL_free(thread);
   1.287      }
   1.288  }
   1.289  
   1.290  Uint32
   1.291 -SDL_GetThreadID (SDL_Thread * thread)
   1.292 +SDL_GetThreadID(SDL_Thread * thread)
   1.293  {
   1.294      Uint32 id;
   1.295  
   1.296      if (thread) {
   1.297          id = thread->threadid;
   1.298      } else {
   1.299 -        id = SDL_ThreadID ();
   1.300 +        id = SDL_ThreadID();
   1.301      }
   1.302      return (id);
   1.303  }
   1.304  
   1.305  void
   1.306 -SDL_KillThread (SDL_Thread * thread)
   1.307 +SDL_KillThread(SDL_Thread * thread)
   1.308  {
   1.309      if (thread) {
   1.310 -        SDL_SYS_KillThread (thread);
   1.311 -        SDL_WaitThread (thread, NULL);
   1.312 +        SDL_SYS_KillThread(thread);
   1.313 +        SDL_WaitThread(thread, NULL);
   1.314      }
   1.315  }
   1.316