28#ifdef MHD_USE_W32_THREADS
29#include "mhd_limits.h"
32#ifdef MHD_USE_THREAD_NAME_
36#ifdef HAVE_PTHREAD_NP_H
37#include <pthread_np.h>
43#ifndef MHD_USE_THREAD_NAME_
45#define MHD_set_thread_name_(t, n) (void)
46#define MHD_set_cur_thread_name_(n) (void)
50#if defined(MHD_USE_POSIX_THREADS)
51#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || \
52 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
53# define MHD_USE_THREAD_ATTR_SETNAME 1
57#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || \
58 defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \
59 || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
70 const char *thread_name)
72 if (
NULL == thread_name)
75#if defined(HAVE_PTHREAD_SETNAME_NP_GNU)
76 return ! pthread_setname_np (thread_id, thread_name);
77#elif defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD)
79 pthread_set_name_np (thread_id, thread_name);
81#elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
87 return ! pthread_setname_np (thread_id, thread_name, 0);
98#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (pthread_self (),(n))
101#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (0,(n))
103#elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN)
110#define MHD_set_cur_thread_name_(n) (! (pthread_setname_np ((n))))
113#elif defined(MHD_USE_W32_THREADS)
126 const char *thread_name)
128 static const DWORD VC_SETNAME_EXC = 0x406D1388;
130 struct thread_info_struct
139 if (
NULL == thread_name)
142 thread_info.type = 0x1000;
143 thread_info.name = thread_name;
144 thread_info.ID = thread_id;
145 thread_info.flags = 0;
149 RaiseException (VC_SETNAME_EXC,
151 sizeof (thread_info) /
sizeof(ULONG_PTR),
152 (ULONG_PTR *) &thread_info);
154 __except (EXCEPTION_EXECUTE_HANDLER)
166#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (-1,(n))
188#if defined(MHD_USE_POSIX_THREADS)
194 res = pthread_attr_init (&attr);
197 res = pthread_attr_setstacksize (&attr,
200 res = pthread_create (&(thread->handle),
204 pthread_attr_destroy (&attr);
208 res = pthread_create (&(thread->handle),
217#elif defined(MHD_USE_W32_THREADS)
218#if SIZEOF_SIZE_T != SIZEOF_UNSIGNED_INT
226 thread->handle = (MHD_thread_handle_)
227 _beginthreadex (
NULL,
228 (
unsigned int) stack_size,
234 if ((MHD_thread_handle_) - 1 == thread->handle)
242#ifdef MHD_USE_THREAD_NAME_
244#ifndef MHD_USE_THREAD_ATTR_SETNAME
245struct MHD_named_helper_param_
264static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
265named_thread_starter (
void *
data)
267 struct MHD_named_helper_param_ *
const param =
268 (
struct MHD_named_helper_param_ *)
data;
273 return (MHD_THRD_RTRN_TYPE_) 0;
278 thr_func = param->start_routine;
281 return thr_func (arg);
300 const char *thread_name,
305#if defined(MHD_USE_THREAD_ATTR_SETNAME)
309 res = pthread_attr_init (&attr);
312#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD)
318 res = pthread_attr_setname_np (&attr,
321#elif defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
322 res = pthread_attr_setname_np (&attr,
325#error No pthread_attr_setname_np() function.
327 if ((res == 0) && (0 != stack_size) )
328 res = pthread_attr_setstacksize (&attr,
331 res = pthread_create (&(thread->handle),
335 pthread_attr_destroy (&attr);
342 struct MHD_named_helper_param_ *param;
344 if (
NULL == thread_name)
350 param = malloc (
sizeof (
struct MHD_named_helper_param_));
354 param->start_routine = start_routine;
356 param->name = thread_name;
363 &named_thread_starter,
int MHD_create_thread_(MHD_thread_handle_ID_ *thread, size_t stack_size, MHD_THREAD_START_ROUTINE_ start_routine, void *arg)
MHD_THRD_RTRN_TYPE_(MHD_THRD_CALL_SPEC_ * MHD_THREAD_START_ROUTINE_)(void *cls)
#define MHD_create_named_thread_(t, n, s, r, a)
#define MHD_set_cur_thread_name_(n)
#define MHD_set_thread_name_(t, n)
Header for platform-independent threads abstraction.