src/thread/SDL_thread.c
changeset 5969 3a041d215edc
parent 5535 96594ac5fd1a
child 6044 35448a5ea044
     1.1 --- a/src/thread/SDL_thread.c	Tue Sep 27 23:16:04 2011 -0400
     1.2 +++ b/src/thread/SDL_thread.c	Sun Oct 02 00:29:16 2011 -0400
     1.3 @@ -188,25 +188,19 @@
     1.4  void
     1.5  SDL_RunThread(void *data)
     1.6  {
     1.7 -    thread_args *args;
     1.8 -    int (SDLCALL * userfunc) (void *);
     1.9 -    void *userdata;
    1.10 -    int *statusloc;
    1.11 +    thread_args *args = (thread_args *) data;
    1.12 +    int (SDLCALL * userfunc) (void *) = args->func;
    1.13 +    void *userdata = args->data;
    1.14 +    int *statusloc = &args->info->status;
    1.15  
    1.16      /* Perform any system-dependent setup
    1.17         - this function cannot fail, and cannot use SDL_SetError()
    1.18       */
    1.19 -    SDL_SYS_SetupThread();
    1.20 +    SDL_SYS_SetupThread(args->info->name);
    1.21  
    1.22      /* Get the thread id */
    1.23 -    args = (thread_args *) data;
    1.24      args->info->threadid = SDL_ThreadID();
    1.25  
    1.26 -    /* Figure out what function to run */
    1.27 -    userfunc = args->func;
    1.28 -    userdata = args->data;
    1.29 -    statusloc = &args->info->status;
    1.30 -
    1.31      /* Wake up the parent thread */
    1.32      SDL_SemPost(args->wait);
    1.33  
    1.34 @@ -217,12 +211,14 @@
    1.35  #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
    1.36  #undef SDL_CreateThread
    1.37  DECLSPEC SDL_Thread *SDLCALL
    1.38 -SDL_CreateThread(int (SDLCALL * fn) (void *), void *data,
    1.39 +SDL_CreateThread(int (SDLCALL * fn) (void *),
    1.40 +                 const char *name, void *data,
    1.41                   pfnSDL_CurrentBeginThread pfnBeginThread,
    1.42                   pfnSDL_CurrentEndThread pfnEndThread)
    1.43  #else
    1.44  DECLSPEC SDL_Thread *SDLCALL
    1.45 -SDL_CreateThread(int (SDLCALL * fn) (void *), void *data)
    1.46 +SDL_CreateThread(int (SDLCALL * fn) (void *),
    1.47 +                 const char *name, void *data)
    1.48  #endif
    1.49  {
    1.50      SDL_Thread *thread;
    1.51 @@ -239,9 +235,20 @@
    1.52      thread->status = -1;
    1.53  
    1.54      /* Set up the arguments for the thread */
    1.55 +    if (name != NULL) {
    1.56 +        thread->name = SDL_strdup(name);
    1.57 +        if (thread->name == NULL) {
    1.58 +            SDL_OutOfMemory();
    1.59 +            SDL_free(thread);
    1.60 +            return (NULL);
    1.61 +        }
    1.62 +    }
    1.63 +
    1.64 +    /* Set up the arguments for the thread */
    1.65      args = (thread_args *) SDL_malloc(sizeof(*args));
    1.66      if (args == NULL) {
    1.67          SDL_OutOfMemory();
    1.68 +        SDL_free(thread->name);
    1.69          SDL_free(thread);
    1.70          return (NULL);
    1.71      }
    1.72 @@ -250,6 +257,7 @@
    1.73      args->info = thread;
    1.74      args->wait = SDL_CreateSemaphore(0);
    1.75      if (args->wait == NULL) {
    1.76 +        SDL_free(thread->name);
    1.77          SDL_free(thread);
    1.78          SDL_free(args);
    1.79          return (NULL);
    1.80 @@ -270,6 +278,7 @@
    1.81      } else {
    1.82          /* Oops, failed.  Gotta free everything */
    1.83          SDL_DelThread(thread);
    1.84 +        SDL_free(thread->name);
    1.85          SDL_free(thread);
    1.86          thread = NULL;
    1.87      }
    1.88 @@ -293,6 +302,12 @@
    1.89      return id;
    1.90  }
    1.91  
    1.92 +const char *
    1.93 +SDL_GetThreadName(SDL_Thread * thread)
    1.94 +{
    1.95 +    return thread->name;
    1.96 +}
    1.97 +
    1.98  int
    1.99  SDL_SetThreadPriority(SDL_ThreadPriority priority)
   1.100  {
   1.101 @@ -308,6 +323,7 @@
   1.102              *status = thread->status;
   1.103          }
   1.104          SDL_DelThread(thread);
   1.105 +        SDL_free(thread->name);
   1.106          SDL_free(thread);
   1.107      }
   1.108  }