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)
84return ! pthread_setname_np (thread_id, thread_name, 0);
95#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (pthread_self (),(n))
98#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (0,(n))
100#elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN)
107#define MHD_set_cur_thread_name_(n) (! (pthread_setname_np ((n))))
110#elif defined(MHD_USE_W32_THREADS)
123 const char *thread_name)
125 static const DWORD VC_SETNAME_EXC = 0x406D1388;
127 struct thread_info_struct
136 if (
NULL == thread_name)
139 thread_info.type = 0x1000;
140 thread_info.name = thread_name;
141 thread_info.ID = thread_id;
142 thread_info.flags = 0;
146 RaiseException (VC_SETNAME_EXC,
148 sizeof (thread_info) /
sizeof(ULONG_PTR),
149 (ULONG_PTR *) &thread_info);
151 __except (EXCEPTION_EXECUTE_HANDLER)
163#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (-1,(n))
185#if defined(MHD_USE_POSIX_THREADS)
191 res = pthread_attr_init (&attr);
194 res = pthread_attr_setstacksize (&attr,
197 res = pthread_create (&(thread->handle),
201 pthread_attr_destroy (&attr);
205 res = pthread_create (&(thread->handle),
214#elif defined(MHD_USE_W32_THREADS)
215#if SIZE_MAX != UINT_MAX
223 thread->handle = (MHD_thread_handle_)
224 _beginthreadex (
NULL,
225 (
unsigned int) stack_size,
231 if ((MHD_thread_handle_) - 1 == thread->handle)
239#ifdef MHD_USE_THREAD_NAME_
241#ifndef MHD_USE_THREAD_ATTR_SETNAME
242struct MHD_named_helper_param_
261static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
262named_thread_starter (
void *
data)
264 struct MHD_named_helper_param_ *
const param =
265 (
struct MHD_named_helper_param_ *)
data;
270 return (MHD_THRD_RTRN_TYPE_) 0;
275 thr_func = param->start_routine;
278 return thr_func (arg);
297 const char *thread_name,
302#if defined(MHD_USE_THREAD_ATTR_SETNAME)
306 res = pthread_attr_init (&attr);
309#if defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD)
314res = pthread_attr_setname_np (&attr, thread_name, 0);
315#elif defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
316 res = pthread_attr_setname_np (&attr, thread_name);
318#error No pthread_attr_setname_np() function.
320 if ((res == 0) && (0 != stack_size) )
321 res = pthread_attr_setstacksize (&attr,
324 res = pthread_create (&(thread->handle),
328 pthread_attr_destroy (&attr);
335 struct MHD_named_helper_param_ *param;
337 if (
NULL == thread_name)
343 param = malloc (
sizeof (
struct MHD_named_helper_param_));
347 param->start_routine = start_routine;
349 param->name = thread_name;
356 &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.