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
54#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || \
55 defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \
56 || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
67 const char *thread_name)
69 if (
NULL == thread_name)
72#if defined(HAVE_PTHREAD_SETNAME_NP_GNU)
73 return ! pthread_setname_np (thread_id, thread_name);
74#elif defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD)
76 pthread_set_name_np (thread_id, thread_name);
78#elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
83return ! pthread_setname_np (thread_id, thread_name, 0);
94#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (pthread_self (),(n))
97#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (0,(n))
99#elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN)
106#define MHD_set_cur_thread_name_(n) (! (pthread_setname_np ((n))))
109#elif defined(MHD_USE_W32_THREADS)
122 const char *thread_name)
124 static const DWORD VC_SETNAME_EXC = 0x406D1388;
126 struct thread_info_struct
135 if (
NULL == thread_name)
138 thread_info.type = 0x1000;
139 thread_info.name = thread_name;
140 thread_info.ID = thread_id;
141 thread_info.flags = 0;
145 RaiseException (VC_SETNAME_EXC,
147 sizeof (thread_info) /
sizeof(ULONG_PTR),
148 (ULONG_PTR *) &thread_info);
150 __except (EXCEPTION_EXECUTE_HANDLER)
162#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (-1,(n))
184#if defined(MHD_USE_POSIX_THREADS)
190 res = pthread_attr_init (&attr);
193 res = pthread_attr_setstacksize (&attr,
196 res = pthread_create (&(thread->handle),
200 pthread_attr_destroy (&attr);
204 res = pthread_create (&(thread->handle),
213#elif defined(MHD_USE_W32_THREADS)
214#if SIZE_MAX != UINT_MAX
222 thread->handle = (MHD_thread_handle_)
223 _beginthreadex (
NULL,
224 (
unsigned int) stack_size,
230 if ((MHD_thread_handle_) - 1 == thread->handle)
238#ifdef MHD_USE_THREAD_NAME_
240#ifndef MHD_USE_THREAD_ATTR_SETNAME
241struct MHD_named_helper_param_
260static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
261named_thread_starter (
void *
data)
263 struct MHD_named_helper_param_ *
const param =
264 (
struct MHD_named_helper_param_ *)
data;
269 return (MHD_THRD_RTRN_TYPE_) 0;
274 thr_func = param->start_routine;
277 return thr_func (arg);
296 const char*thread_name,
301#if defined(MHD_USE_THREAD_ATTR_SETNAME)
305 res = pthread_attr_init (&attr);
308#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD)
313res = pthread_attr_setname_np (&attr, thread_name, 0);
314#elif defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
315 res = pthread_attr_setname_np (&attr, thread_name);
317#error No pthread_attr_setname_np() function.
319 if ((res == 0) && (0 != stack_size) )
320 res = pthread_attr_setstacksize (&attr,
323 res = pthread_create (&(thread->handle),
327 pthread_attr_destroy (&attr);
334 struct MHD_named_helper_param_ *param;
336 if (
NULL == thread_name)
342 param = malloc (
sizeof (
struct MHD_named_helper_param_));
346 param->start_routine = start_routine;
348 param->name = thread_name;
355 &named_thread_starter,
int MHD_create_thread_(MHD_thread_handle_ID_ *thread, size_t stack_size, MHD_THREAD_START_ROUTINE_ start_routine, void *arg)
#define MHD_set_cur_thread_name_(n)
#define MHD_set_thread_name_(t, n)
MHD_THRD_RTRN_TYPE_(MHD_THRD_CALL_SPEC_ * MHD_THREAD_START_ROUTINE_)(void *cls)
#define MHD_create_named_thread_(t, n, s, r, a)
Header for platform-independent threads abstraction.