src/thread/pthread/SDL_systhread.c
changeset 5969 3a041d215edc
parent 5963 fe5d2285dffa
child 5972 8b7f8d297943
     1.1 --- a/src/thread/pthread/SDL_systhread.c	Tue Sep 27 23:16:04 2011 -0400
     1.2 +++ b/src/thread/pthread/SDL_systhread.c	Sun Oct 02 00:29:16 2011 -0400
     1.3 @@ -21,6 +21,11 @@
     1.4  #include "SDL_config.h"
     1.5  
     1.6  #include <pthread.h>
     1.7 +
     1.8 +#if HAVE_PTHREAD_NP_H
     1.9 +#include <pthread_np.h>
    1.10 +#endif
    1.11 +
    1.12  #include <signal.h>
    1.13  #ifdef __LINUX__
    1.14  #include <sys/time.h>
    1.15 @@ -28,6 +33,7 @@
    1.16  #include <sys/syscall.h>
    1.17  #endif
    1.18  
    1.19 +#include "SDL_platform.h"
    1.20  #include "SDL_thread.h"
    1.21  #include "../SDL_thread_c.h"
    1.22  #include "../SDL_systhread.h"
    1.23 @@ -67,12 +73,27 @@
    1.24      return (0);
    1.25  }
    1.26  
    1.27 +/* make pthread_setname_np() a weak reference even without SDK support. */
    1.28 +#if __MACOSX__ && (MAC_OS_X_VERSION_MAX_ALLOWED < 1060)
    1.29 +int pthread_setname_np(const char*) __attribute__((weak_import,visibility("default")));
    1.30 +#elif __IPHONEOS__ && (__IPHONE_OS_VERSION_MAX_ALLOWED < 30200)
    1.31 +int pthread_setname_np(const char*) __attribute__((weak_import));
    1.32 +#endif
    1.33 +
    1.34  void
    1.35 -SDL_SYS_SetupThread(void)
    1.36 +SDL_SYS_SetupThread(const char *name)
    1.37  {
    1.38      int i;
    1.39      sigset_t mask;
    1.40  
    1.41 +#if __MACOSX__ || __IPHONEOS__
    1.42 +    if (pthread_setname_np != NULL) { pthread_setname_np(name); }
    1.43 +#elif HAVE_PTHREAD_SETNAME_NP
    1.44 +    pthread_setname_np(pthread_self(), name);
    1.45 +#elif HAVE_PTHREAD_SET_NAME_NP
    1.46 +    pthread_set_name_np(pthread_self(), name);
    1.47 +#endif
    1.48 +
    1.49      /* Mask asynchronous signals for this thread */
    1.50      sigemptyset(&mask);
    1.51      for (i = 0; sig_list[i]; ++i) {