diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2012-11-27 11:15:01 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2012-11-27 11:15:01 +0100 |
commit | a7deb5656b52ef9a8126998398e06154378e88f1 (patch) | |
tree | 6d07870dbdbdb03b19b30dfc24ece924f2152424 | |
parent | 5c1e61da7d6e71a6eef459fb7ecaafacd0a4a4d3 (diff) | |
download | lanes-a7deb5656b52ef9a8126998398e06154378e88f1.tar.gz lanes-a7deb5656b52ef9a8126998398e06154378e88f1.tar.bz2 lanes-a7deb5656b52ef9a8126998398e06154378e88f1.zip |
Use prctl when pthread_setname_np isn't available
-rw-r--r-- | src/threading.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/threading.c b/src/threading.c index edfae90..da33879 100644 --- a/src/threading.c +++ b/src/threading.c | |||
@@ -57,6 +57,17 @@ THE SOFTWARE. | |||
57 | volatile bool_t sudo; | 57 | volatile bool_t sudo; |
58 | #endif | 58 | #endif |
59 | 59 | ||
60 | /* Linux with older glibc (such as Debian) don't have pthread_setname_np, but have prctl | ||
61 | */ | ||
62 | #if defined PLATFORM_LINUX | ||
63 | #if defined __GNU_LIBRARY__ && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 12 | ||
64 | #define LINUX_USE_PTHREAD_SETNAME_NP 1 | ||
65 | #else // glibc without pthread_setname_np | ||
66 | #include <sys/prctl.h> | ||
67 | #define LINUX_USE_PTHREAD_SETNAME_NP 0 | ||
68 | #endif // glibc without pthread_setname_np | ||
69 | #endif // PLATFORM_LINUX | ||
70 | |||
60 | #ifdef _MSC_VER | 71 | #ifdef _MSC_VER |
61 | // ".. selected for automatic inline expansion" (/O2 option) | 72 | // ".. selected for automatic inline expansion" (/O2 option) |
62 | # pragma warning( disable : 4711 ) | 73 | # pragma warning( disable : 4711 ) |
@@ -777,7 +788,13 @@ bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T * | |||
777 | // if you need to fix the build, or if you know how to fill a hole, tell me (bnt.germain@gmail.com) so that I can submit the fix in github. | 788 | // if you need to fix the build, or if you know how to fill a hole, tell me (bnt.germain@gmail.com) so that I can submit the fix in github. |
778 | #if defined PLATFORM_BSD | 789 | #if defined PLATFORM_BSD |
779 | pthread_set_name_np( pthread_self(), _name); | 790 | pthread_set_name_np( pthread_self(), _name); |
780 | #elif defined PLATFORM_LINUX || defined PLATFORM_QNX || defined PLATFORM_CYGWIN | 791 | #elif defined PLATFORM_LINUX |
792 | #if LINUX_USE_PTHREAD_SETNAME_NP | ||
793 | pthread_setname_np( pthread_self(), _name); | ||
794 | #else // LINUX_USE_PTHREAD_SETNAME_NP | ||
795 | prctl(PR_SET_NAME, _name, 0, 0, 0); | ||
796 | #endif // LINUX_USE_PTHREAD_SETNAME_NP | ||
797 | #elif defined PLATFORM_QNX || defined PLATFORM_CYGWIN | ||
781 | pthread_setname_np( pthread_self(), _name); | 798 | pthread_setname_np( pthread_self(), _name); |
782 | #elif defined PLATFORM_OSX | 799 | #elif defined PLATFORM_OSX |
783 | pthread_setname_np(_name); | 800 | pthread_setname_np(_name); |