aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_threads.c
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-11-11 13:18:18 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-11-11 20:56:38 +0300
commit280232dc1e9a6e26b13530c5e576880151935b19 (patch)
tree6ad50727f8c78974520915b92a15e1c97846cfa6 /src/microhttpd/mhd_threads.c
parent631a581657a7f2896f8b5ab7f1ea92c6997fc6c4 (diff)
downloadlibmicrohttpd-280232dc1e9a6e26b13530c5e576880151935b19.tar.gz
libmicrohttpd-280232dc1e9a6e26b13530c5e576880151935b19.zip
Added support for faster setting thread names by pthread_attr_setname_np() where available.
Diffstat (limited to 'src/microhttpd/mhd_threads.c')
-rw-r--r--src/microhttpd/mhd_threads.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/microhttpd/mhd_threads.c b/src/microhttpd/mhd_threads.c
index 10f486a1..dffbfd00 100644
--- a/src/microhttpd/mhd_threads.c
+++ b/src/microhttpd/mhd_threads.c
@@ -54,6 +54,10 @@ typedef DWORD MHD_thread_ID_;
54#else /* MHD_USE_THREAD_NAME_ */ 54#else /* MHD_USE_THREAD_NAME_ */
55 55
56#if defined(MHD_USE_POSIX_THREADS) 56#if defined(MHD_USE_POSIX_THREADS)
57#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
58# define MHD_USE_THREAD_ATTR_SETNAME 1
59#endif /* HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD || HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI */
60
57#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \ 61#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \
58 || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) 62 || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
59 63
@@ -237,6 +241,7 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
237 241
238#ifdef MHD_USE_THREAD_NAME_ 242#ifdef MHD_USE_THREAD_NAME_
239 243
244#ifndef MHD_USE_THREAD_ATTR_SETNAME
240struct MHD_named_helper_param_ 245struct MHD_named_helper_param_
241{ 246{
242 /** 247 /**
@@ -275,6 +280,7 @@ named_thread_starter (void *data)
275 280
276 return thr_func(arg); 281 return thr_func(arg);
277} 282}
283#endif /* ! MHD_USE_THREAD_ATTR_SETNAME */
278 284
279 285
280/** 286/**
@@ -294,6 +300,40 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread,
294 MHD_THREAD_START_ROUTINE_ start_routine, 300 MHD_THREAD_START_ROUTINE_ start_routine,
295 void *arg) 301 void *arg)
296{ 302{
303#if defined(MHD_USE_THREAD_ATTR_SETNAME)
304 int res;
305 pthread_attr_t attr;
306
307 res = pthread_attr_init (&attr);
308 if (0 == res)
309 {
310#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD)
311 /* NetBSD use 3 arguments: second argument is string in printf-like format,
312 * third argument is single argument for printf;
313 * OSF1 use 3 arguments too, but last one always must be zero (NULL).
314 * MHD doesn't use '%' in thread names, so both form are used in same way.
315 */
316 res = pthread_attr_setname_np (&attr, thread_name, 0);
317#elif defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
318 res = pthread_attr_setname_np (&attr, thread_name);
319#else
320#error No pthread_attr_setname_np() function.
321#endif
322 if (res == 0 && 0 != stack_size)
323 res = pthread_attr_setstacksize (&attr,
324 stack_size);
325 if (0 == res)
326 res = pthread_create (thread,
327 &attr,
328 start_routine,
329 arg);
330 pthread_attr_destroy (&attr);
331 }
332 if (0 != res)
333 errno = res;
334
335 return !res;
336#else /* ! MHD_USE_THREAD_ATTR_SETNAME */
297 struct MHD_named_helper_param_ *param; 337 struct MHD_named_helper_param_ *param;
298 338
299 if (NULL == thread_name) 339 if (NULL == thread_name)
@@ -323,6 +363,7 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread,
323 } 363 }
324 364
325 return !0; 365 return !0;
366#endif /* ! MHD_USE_THREAD_ATTR_SETNAME */
326} 367}
327 368
328#endif /* MHD_USE_THREAD_NAME_ */ 369#endif /* MHD_USE_THREAD_NAME_ */