28 #ifdef MHD_USE_W32_THREADS 32 #ifdef MHD_USE_THREAD_NAME_ 34 #ifdef HAVE_PTHREAD_NP_H 35 #include <pthread_np.h> 42 #if defined(MHD_USE_POSIX_THREADS) 43 typedef pthread_t MHD_thread_ID_;
44 #elif defined(MHD_USE_W32_THREADS) 45 typedef DWORD MHD_thread_ID_;
49 #ifndef MHD_USE_THREAD_NAME_ 51 #define MHD_set_thread_name_(t, n) (void) 52 #define MHD_set_cur_thread_name_(n) (void) 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 61 #if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \ 62 || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) 73 const char *thread_name)
75 if (
NULL == thread_name)
78 #if defined(HAVE_PTHREAD_SETNAME_NP_GNU) 79 return !pthread_setname_np (thread_id, thread_name);
80 #elif defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) 82 pthread_set_name_np (thread_id, thread_name);
84 #elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) 90 return !pthread_setname_np (thread_id, thread_name, 0);
101 #define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(pthread_self(),(n)) 104 #define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(0,(n)) 106 #elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) 113 #define MHD_set_cur_thread_name_(n) (!(pthread_setname_np((n)))) 116 #elif defined(MHD_USE_W32_THREADS) 117 #ifndef _MSC_FULL_VER 129 const char *thread_name)
131 static const DWORD VC_SETNAME_EXC = 0x406D1388;
133 struct thread_info_struct
142 if (
NULL == thread_name)
145 thread_info.type = 0x1000;
146 thread_info.name = thread_name;
147 thread_info.ID = thread_id;
148 thread_info.flags = 0;
152 RaiseException (VC_SETNAME_EXC,
154 sizeof (thread_info) /
sizeof(ULONG_PTR),
155 (ULONG_PTR *) &thread_info);
157 __except (EXCEPTION_EXECUTE_HANDLER)
169 #define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(-1,(n)) 191 #if defined(MHD_USE_POSIX_THREADS) 197 res = pthread_attr_init (&attr);
200 res = pthread_attr_setstacksize (&attr,
203 res = pthread_create (thread,
207 pthread_attr_destroy (&attr);
211 res = pthread_create (thread,
220 #elif defined(MHD_USE_W32_THREADS) 221 #if SIZE_MAX != UINT_MAX 229 *thread = (HANDLE) _beginthreadex (
NULL,
230 (
unsigned int) stack_size,
235 if ((MHD_thread_handle_)-1 == (*thread))
242 #ifdef MHD_USE_THREAD_NAME_ 244 #ifndef MHD_USE_THREAD_ATTR_SETNAME 245 struct MHD_named_helper_param_
264 static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
265 named_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);
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, thread_name, 0);
317 #elif defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) 318 res = pthread_attr_setname_np (&attr, thread_name);
320 #error No pthread_attr_setname_np() function. 322 if (res == 0 && 0 != stack_size)
323 res = pthread_attr_setstacksize (&attr,
326 res = pthread_create (thread,
330 pthread_attr_destroy (&attr);
337 struct MHD_named_helper_param_ *param;
339 if (
NULL == thread_name)
345 param = malloc (
sizeof (
struct MHD_named_helper_param_));
349 param->start_routine = start_routine;
351 param->name = thread_name;
358 &named_thread_starter,
#define MHD_set_thread_name_(t, n)
int MHD_create_thread_(MHD_thread_handle_ *thread, size_t stack_size, MHD_THREAD_START_ROUTINE_ start_routine, void *arg)
#define MHD_create_named_thread_(t, n, s, r, a)
#define MHD_set_cur_thread_name_(n)
limits values definitions
Header for platform-independent threads abstraction.
MHD_THRD_RTRN_TYPE_(MHD_THRD_CALL_SPEC_ * MHD_THREAD_START_ROUTINE_)(void *cls)