diff options
Diffstat (limited to 'src/microhttpd/mhd_threads.c')
-rw-r--r-- | src/microhttpd/mhd_threads.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/microhttpd/mhd_threads.c b/src/microhttpd/mhd_threads.c index 07da4960..713c8348 100644 --- a/src/microhttpd/mhd_threads.c +++ b/src/microhttpd/mhd_threads.c | |||
@@ -31,6 +31,9 @@ | |||
31 | #endif | 31 | #endif |
32 | #ifdef MHD_USE_THREAD_NAME_ | 32 | #ifdef MHD_USE_THREAD_NAME_ |
33 | #include <stdlib.h> | 33 | #include <stdlib.h> |
34 | #ifdef HAVE_PTHREAD_NP_H | ||
35 | #include <pthread_np.h> | ||
36 | #endif /* HAVE_PTHREAD_NP_H */ | ||
34 | #endif /* MHD_USE_THREAD_NAME_ */ | 37 | #endif /* MHD_USE_THREAD_NAME_ */ |
35 | #include <errno.h> | 38 | #include <errno.h> |
36 | 39 | ||
@@ -51,7 +54,8 @@ typedef DWORD MHD_thread_ID_; | |||
51 | #else /* MHD_USE_THREAD_NAME_ */ | 54 | #else /* MHD_USE_THREAD_NAME_ */ |
52 | 55 | ||
53 | #if defined(MHD_USE_POSIX_THREADS) | 56 | #if defined(MHD_USE_POSIX_THREADS) |
54 | #ifdef HAVE_PTHREAD_SETNAME_NP | 57 | #if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \ |
58 | || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) | ||
55 | /** | 59 | /** |
56 | * Set thread name | 60 | * Set thread name |
57 | * @param thread_id ID of thread | 61 | * @param thread_id ID of thread |
@@ -63,16 +67,38 @@ static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thre | |||
63 | if (NULL == thread_name) | 67 | if (NULL == thread_name) |
64 | return 0; | 68 | return 0; |
65 | 69 | ||
70 | #if defined(HAVE_PTHREAD_SETNAME_NP_GNU) | ||
66 | return !pthread_setname_np (thread_id, thread_name); | 71 | return !pthread_setname_np (thread_id, thread_name); |
72 | #elif defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) | ||
73 | /* FreeBSD and OpenBSD use different name and void return type */ | ||
74 | pthread_set_name_np (thread_id, thread_name); | ||
75 | return !0; | ||
76 | #elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) | ||
77 | /* NetBSD use 3 arguments: second argument is string in printf-like format, | ||
78 | * third argument is single argument for printf; | ||
79 | * OSF1 use 3 arguments too, but last one always must be zero (NULL). | ||
80 | * MHD doesn't use '%' in thread names, so both form are used in same way. | ||
81 | */ | ||
82 | return !pthread_setname_np (thread_id, thread_name, 0); | ||
83 | #endif /* HAVE_PTHREAD_SETNAME_NP_NETBSD */ | ||
67 | } | 84 | } |
68 | 85 | ||
86 | |||
69 | /** | 87 | /** |
70 | * Set current thread name | 88 | * Set current thread name |
71 | * @param n name to set | 89 | * @param n name to set |
72 | * @return non-zero on success, zero otherwise | 90 | * @return non-zero on success, zero otherwise |
73 | */ | 91 | */ |
74 | #define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(pthread_self(),(n)) | 92 | #define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(pthread_self(),(n)) |
75 | #endif /* HAVE_PTHREAD_SETNAME_NP */ | 93 | #elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) |
94 | |||
95 | /** | ||
96 | * Set current thread name | ||
97 | * @param n name to set | ||
98 | * @return non-zero on success, zero otherwise | ||
99 | */ | ||
100 | #define MHD_set_cur_thread_name_(n) (!(pthread_setname_np((n)))) | ||
101 | #endif /* HAVE_PTHREAD_SETNAME_NP_DARWIN */ | ||
76 | 102 | ||
77 | #elif defined(MHD_USE_W32_THREADS) | 103 | #elif defined(MHD_USE_W32_THREADS) |
78 | #ifndef _MSC_FULL_VER | 104 | #ifndef _MSC_FULL_VER |