diff options
Diffstat (limited to 'src/microhttpd/mhd_threads.c')
-rw-r--r-- | src/microhttpd/mhd_threads.c | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/src/microhttpd/mhd_threads.c b/src/microhttpd/mhd_threads.c index 80a320c8..6f2e34ce 100644 --- a/src/microhttpd/mhd_threads.c +++ b/src/microhttpd/mhd_threads.c | |||
@@ -56,13 +56,17 @@ typedef DWORD MHD_thread_ID_; | |||
56 | #if defined(MHD_USE_POSIX_THREADS) | 56 | #if defined(MHD_USE_POSIX_THREADS) |
57 | #if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \ | 57 | #if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \ |
58 | || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) | 58 | || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) |
59 | |||
59 | /** | 60 | /** |
60 | * Set thread name | 61 | * Set thread name |
62 | * | ||
61 | * @param thread_id ID of thread | 63 | * @param thread_id ID of thread |
62 | * @param thread_name name to set | 64 | * @param thread_name name to set |
63 | * @return non-zero on success, zero otherwise | 65 | * @return non-zero on success, zero otherwise |
64 | */ | 66 | */ |
65 | static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thread_name) | 67 | static int |
68 | MHD_set_thread_name_(const MHD_thread_ID_ thread_id, | ||
69 | const char *thread_name) | ||
66 | { | 70 | { |
67 | if (NULL == thread_name) | 71 | if (NULL == thread_name) |
68 | return 0; | 72 | return 0; |
@@ -110,11 +114,14 @@ static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thre | |||
110 | #else /* _MSC_FULL_VER */ | 114 | #else /* _MSC_FULL_VER */ |
111 | /** | 115 | /** |
112 | * Set thread name | 116 | * Set thread name |
117 | * | ||
113 | * @param thread_id ID of thread, -1 for current thread | 118 | * @param thread_id ID of thread, -1 for current thread |
114 | * @param thread_name name to set | 119 | * @param thread_name name to set |
115 | * @return non-zero on success, zero otherwise | 120 | * @return non-zero on success, zero otherwise |
116 | */ | 121 | */ |
117 | static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thread_name) | 122 | static int |
123 | MHD_set_thread_name_(const MHD_thread_ID_ thread_id, | ||
124 | const char *thread_name) | ||
118 | { | 125 | { |
119 | static const DWORD VC_SETNAME_EXC = 0x406D1388; | 126 | static const DWORD VC_SETNAME_EXC = 0x406D1388; |
120 | #pragma pack(push,8) | 127 | #pragma pack(push,8) |
@@ -137,7 +144,10 @@ static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thre | |||
137 | 144 | ||
138 | __try | 145 | __try |
139 | { /* This exception is intercepted by debugger */ | 146 | { /* This exception is intercepted by debugger */ |
140 | RaiseException(VC_SETNAME_EXC, 0, sizeof(thread_info) / sizeof(ULONG_PTR), (ULONG_PTR*)&thread_info); | 147 | RaiseException (VC_SETNAME_EXC, |
148 | 0, | ||
149 | sizeof (thread_info) / sizeof(ULONG_PTR), | ||
150 | (ULONG_PTR *) &thread_info); | ||
141 | } | 151 | } |
142 | __except (EXCEPTION_EXECUTE_HANDLER) | 152 | __except (EXCEPTION_EXECUTE_HANDLER) |
143 | {} | 153 | {} |
@@ -182,15 +192,21 @@ MHD_create_thread_ (MHD_thread_handle_ *thread, | |||
182 | res = pthread_attr_init (&attr); | 192 | res = pthread_attr_init (&attr); |
183 | if (0 == res) | 193 | if (0 == res) |
184 | { | 194 | { |
185 | res = pthread_attr_setstacksize (&attr, stack_size); | 195 | res = pthread_attr_setstacksize (&attr, |
196 | stack_size); | ||
186 | if (0 == res) | 197 | if (0 == res) |
187 | res = pthread_create (thread, &attr, | 198 | res = pthread_create (thread, |
188 | start_routine, arg); | 199 | &attr, |
200 | start_routine, | ||
201 | arg); | ||
189 | pthread_attr_destroy (&attr); | 202 | pthread_attr_destroy (&attr); |
190 | } | 203 | } |
191 | } | 204 | } |
192 | else | 205 | else |
193 | res = pthread_create (thread, NULL, start_routine, arg); | 206 | res = pthread_create (thread, |
207 | NULL, | ||
208 | start_routine, | ||
209 | arg); | ||
194 | 210 | ||
195 | if (0 != res) | 211 | if (0 != res) |
196 | errno = res; | 212 | errno = res; |
@@ -205,8 +221,12 @@ MHD_create_thread_ (MHD_thread_handle_ *thread, | |||
205 | } | 221 | } |
206 | #endif /* SIZE_MAX != UINT_MAX */ | 222 | #endif /* SIZE_MAX != UINT_MAX */ |
207 | 223 | ||
208 | *thread = (HANDLE)_beginthreadex(NULL, (unsigned)stack_size, start_routine, | 224 | *thread = (HANDLE) _beginthreadex (NULL, |
209 | arg, 0, NULL); | 225 | (unsigned int) stack_size, |
226 | start_routine, | ||
227 | arg, | ||
228 | 0, | ||
229 | NULL); | ||
210 | if ((MHD_thread_handle_)-1 == (*thread)) | 230 | if ((MHD_thread_handle_)-1 == (*thread)) |
211 | return 0; | 231 | return 0; |
212 | 232 | ||
@@ -234,6 +254,7 @@ struct MHD_named_helper_param_ | |||
234 | const char *name; | 254 | const char *name; |
235 | }; | 255 | }; |
236 | 256 | ||
257 | |||
237 | static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ | 258 | static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ |
238 | named_thread_starter (void *data) | 259 | named_thread_starter (void *data) |
239 | { | 260 | { |
@@ -245,7 +266,7 @@ named_thread_starter (void *data) | |||
245 | if (NULL == data) | 266 | if (NULL == data) |
246 | return (MHD_THRD_RTRN_TYPE_)0; | 267 | return (MHD_THRD_RTRN_TYPE_)0; |
247 | 268 | ||
248 | MHD_set_cur_thread_name_(param->name); | 269 | MHD_set_cur_thread_name_ (param->name); |
249 | 270 | ||
250 | arg = param->arg; | 271 | arg = param->arg; |
251 | thr_func = param->start_routine; | 272 | thr_func = param->start_routine; |
@@ -255,7 +276,6 @@ named_thread_starter (void *data) | |||
255 | } | 276 | } |
256 | 277 | ||
257 | 278 | ||
258 | |||
259 | /** | 279 | /** |
260 | * Create a named thread and set the attributes according to our options. | 280 | * Create a named thread and set the attributes according to our options. |
261 | * | 281 | * |
@@ -273,7 +293,7 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread, | |||
273 | MHD_THREAD_START_ROUTINE_ start_routine, | 293 | MHD_THREAD_START_ROUTINE_ start_routine, |
274 | void *arg) | 294 | void *arg) |
275 | { | 295 | { |
276 | struct MHD_named_helper_param_ * param; | 296 | struct MHD_named_helper_param_ *param; |
277 | 297 | ||
278 | if (NULL == thread_name) | 298 | if (NULL == thread_name) |
279 | { | 299 | { |
@@ -281,7 +301,7 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread, | |||
281 | return 0; | 301 | return 0; |
282 | } | 302 | } |
283 | 303 | ||
284 | param = malloc(sizeof(struct MHD_named_helper_param_)); | 304 | param = malloc (sizeof (struct MHD_named_helper_param_)); |
285 | if (NULL == param) | 305 | if (NULL == param) |
286 | return 0; | 306 | return 0; |
287 | 307 | ||
@@ -292,9 +312,12 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread, | |||
292 | /* Set thread name in thread itself to avoid problems with | 312 | /* Set thread name in thread itself to avoid problems with |
293 | * threads which terminated before name is set in other thread. | 313 | * threads which terminated before name is set in other thread. |
294 | */ | 314 | */ |
295 | if (!MHD_create_thread_(thread, stack_size, &named_thread_starter, (void*)param)) | 315 | if (! MHD_create_thread_(thread, |
316 | stack_size, | ||
317 | &named_thread_starter, | ||
318 | (void*)param)) | ||
296 | { | 319 | { |
297 | free(param); | 320 | free (param); |
298 | return 0; | 321 | return 0; |
299 | } | 322 | } |
300 | 323 | ||