28 #ifdef MHD_USE_W32_THREADS
29 #include "mhd_limits.h"
32 #ifdef MHD_USE_THREAD_NAME_
34 #ifdef HAVE_PTHREAD_NP_H
35 #include <pthread_np.h>
41 #ifndef MHD_USE_THREAD_NAME_
43 #define MHD_set_thread_name_(t, n) (void)
44 #define MHD_set_cur_thread_name_(n) (void)
48 #if defined(MHD_USE_POSIX_THREADS)
49 #if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || \
50 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
51 # define MHD_USE_THREAD_ATTR_SETNAME 1
55 #if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || \
56 defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \
57 || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
68 const char *thread_name)
70 if (
NULL == thread_name)
73 #if defined(HAVE_PTHREAD_SETNAME_NP_GNU)
74 return ! pthread_setname_np (thread_id, thread_name);
75 #elif defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD)
77 pthread_set_name_np (thread_id, thread_name);
79 #elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
85 return ! pthread_setname_np (thread_id, thread_name, 0);
96 #define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (pthread_self (),(n))
99 #define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (0,(n))
101 #elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN)
108 #define MHD_set_cur_thread_name_(n) (! (pthread_setname_np ((n))))
111 #elif defined(MHD_USE_W32_THREADS)
112 #ifndef _MSC_FULL_VER
124 const char *thread_name)
126 static const DWORD VC_SETNAME_EXC = 0x406D1388;
128 struct thread_info_struct
137 if (
NULL == thread_name)
140 thread_info.type = 0x1000;
141 thread_info.name = thread_name;
142 thread_info.ID = thread_id;
143 thread_info.flags = 0;
147 RaiseException (VC_SETNAME_EXC,
149 sizeof (thread_info) /
sizeof(ULONG_PTR),
150 (ULONG_PTR *) &thread_info);
152 __except (EXCEPTION_EXECUTE_HANDLER)
164 #define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (-1,(n))
186 #if defined(MHD_USE_POSIX_THREADS)
192 res = pthread_attr_init (&attr);
195 res = pthread_attr_setstacksize (&attr,
198 res = pthread_create (&(thread->handle),
202 pthread_attr_destroy (&attr);
206 res = pthread_create (&(thread->handle),
215 #elif defined(MHD_USE_W32_THREADS)
216 #if SIZE_MAX != UINT_MAX
224 thread->handle = (MHD_thread_handle_)
225 _beginthreadex (
NULL,
226 (
unsigned int) stack_size,
232 if ((MHD_thread_handle_) - 1 == thread->handle)
240 #ifdef MHD_USE_THREAD_NAME_
242 #ifndef MHD_USE_THREAD_ATTR_SETNAME
243 struct MHD_named_helper_param_
262 static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
263 named_thread_starter (
void *
data)
265 struct MHD_named_helper_param_ *
const param =
266 (
struct MHD_named_helper_param_ *)
data;
271 return (MHD_THRD_RTRN_TYPE_) 0;
276 thr_func = param->start_routine;
279 return thr_func (arg);
298 const char*thread_name,
303 #if defined(MHD_USE_THREAD_ATTR_SETNAME)
307 res = pthread_attr_init (&attr);
310 #if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD)
316 res = pthread_attr_setname_np (&attr,
319 #elif defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
320 res = pthread_attr_setname_np (&attr,
323 #error No pthread_attr_setname_np() function.
325 if ((res == 0) && (0 != stack_size) )
326 res = pthread_attr_setstacksize (&attr,
329 res = pthread_create (&(thread->handle),
333 pthread_attr_destroy (&attr);
340 struct MHD_named_helper_param_ *param;
342 if (
NULL == thread_name)
348 param = malloc (
sizeof (
struct MHD_named_helper_param_));
352 param->start_routine = start_routine;
354 param->name = thread_name;
361 &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.