aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/microhttpd/daemon.c8
-rw-r--r--src/microhttpd/internal.h4
-rw-r--r--src/microhttpd/mhd_threads.c28
-rw-r--r--src/microhttpd/mhd_threads.h26
4 files changed, 42 insertions, 24 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 88dabed5..2f8945c1 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2962,7 +2962,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
2962 2962
2963 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 2963 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2964 (! pos->thread_joined) && 2964 (! pos->thread_joined) &&
2965 (! MHD_join_thread_ (pos->pid)) ) 2965 (! MHD_join_thread_ (pos->pid.handle)) )
2966 MHD_PANIC (_("Failed to join a thread\n")); 2966 MHD_PANIC (_("Failed to join a thread\n"));
2967#ifdef UPGRADE_SUPPORT 2967#ifdef UPGRADE_SUPPORT
2968 cleanup_upgraded_connection (pos); 2968 cleanup_upgraded_connection (pos);
@@ -6131,7 +6131,7 @@ close_all_connections (struct MHD_Daemon *daemon)
6131 if (! pos->thread_joined) 6131 if (! pos->thread_joined)
6132 { 6132 {
6133 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 6133 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
6134 if (! MHD_join_thread_ (pos->pid)) 6134 if (! MHD_join_thread_ (pos->pid.handle))
6135 MHD_PANIC (_("Failed to join a thread\n")); 6135 MHD_PANIC (_("Failed to join a thread\n"));
6136 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 6136 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
6137 pos->thread_joined = true; 6137 pos->thread_joined = true;
@@ -6218,7 +6218,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
6218 /* Start harvesting. */ 6218 /* Start harvesting. */
6219 for (i = 0; i < daemon->worker_pool_size; ++i) 6219 for (i = 0; i < daemon->worker_pool_size; ++i)
6220 { 6220 {
6221 if (! MHD_join_thread_ (daemon->worker_pool[i].pid)) 6221 if (! MHD_join_thread_ (daemon->worker_pool[i].pid.handle))
6222 MHD_PANIC (_("Failed to join a thread\n")); 6222 MHD_PANIC (_("Failed to join a thread\n"));
6223#ifdef EPOLL_SUPPORT 6223#ifdef EPOLL_SUPPORT
6224 if (-1 != daemon->worker_pool[i].epoll_fd) 6224 if (-1 != daemon->worker_pool[i].epoll_fd)
@@ -6252,7 +6252,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
6252 SHUT_RDWR); 6252 SHUT_RDWR);
6253 } 6253 }
6254#endif 6254#endif
6255 if (! MHD_join_thread_ (daemon->pid)) 6255 if (! MHD_join_thread_ (daemon->pid.handle))
6256 { 6256 {
6257 MHD_PANIC (_("Failed to join a thread\n")); 6257 MHD_PANIC (_("Failed to join a thread\n"));
6258 } 6258 }
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 85fe2487..602a5d4f 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -755,7 +755,7 @@ struct MHD_Connection
755 * Thread handle for this connection (if we are using 755 * Thread handle for this connection (if we are using
756 * one thread per connection). 756 * one thread per connection).
757 */ 757 */
758 MHD_thread_handle_ pid; 758 MHD_thread_handle_ID_ pid;
759 759
760 /** 760 /**
761 * Size of @e read_buffer (in bytes). This value indicates 761 * Size of @e read_buffer (in bytes). This value indicates
@@ -1442,7 +1442,7 @@ struct MHD_Daemon
1442 /** 1442 /**
1443 * The select thread handle (if we have internal select) 1443 * The select thread handle (if we have internal select)
1444 */ 1444 */
1445 MHD_thread_handle_ pid; 1445 MHD_thread_handle_ID_ pid;
1446 1446
1447 /** 1447 /**
1448 * Mutex for per-IP connection counts. 1448 * Mutex for per-IP connection counts.
diff --git a/src/microhttpd/mhd_threads.c b/src/microhttpd/mhd_threads.c
index dffbfd00..477080cf 100644
--- a/src/microhttpd/mhd_threads.c
+++ b/src/microhttpd/mhd_threads.c
@@ -38,14 +38,6 @@
38#include <errno.h> 38#include <errno.h>
39 39
40 40
41
42#if defined(MHD_USE_POSIX_THREADS)
43typedef pthread_t MHD_thread_ID_;
44#elif defined(MHD_USE_W32_THREADS)
45typedef DWORD MHD_thread_ID_;
46#endif
47
48
49#ifndef MHD_USE_THREAD_NAME_ 41#ifndef MHD_USE_THREAD_NAME_
50 42
51#define MHD_set_thread_name_(t, n) (void) 43#define MHD_set_thread_name_(t, n) (void)
@@ -183,7 +175,7 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
183 * @return non-zero on success; zero otherwise (with errno set) 175 * @return non-zero on success; zero otherwise (with errno set)
184 */ 176 */
185int 177int
186MHD_create_thread_ (MHD_thread_handle_ *thread, 178MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
187 size_t stack_size, 179 size_t stack_size,
188 MHD_THREAD_START_ROUTINE_ start_routine, 180 MHD_THREAD_START_ROUTINE_ start_routine,
189 void *arg) 181 void *arg)
@@ -200,7 +192,7 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
200 res = pthread_attr_setstacksize (&attr, 192 res = pthread_attr_setstacksize (&attr,
201 stack_size); 193 stack_size);
202 if (0 == res) 194 if (0 == res)
203 res = pthread_create (thread, 195 res = pthread_create (&(thread->handle),
204 &attr, 196 &attr,
205 start_routine, 197 start_routine,
206 arg); 198 arg);
@@ -208,7 +200,7 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
208 } 200 }
209 } 201 }
210 else 202 else
211 res = pthread_create (thread, 203 res = pthread_create (&(thread->handle),
212 NULL, 204 NULL,
213 start_routine, 205 start_routine,
214 arg); 206 arg);
@@ -218,6 +210,7 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
218 210
219 return !res; 211 return !res;
220#elif defined(MHD_USE_W32_THREADS) 212#elif defined(MHD_USE_W32_THREADS)
213 unsigned int thread_ID;
221#if SIZE_MAX != UINT_MAX 214#if SIZE_MAX != UINT_MAX
222 if (stack_size > UINT_MAX) 215 if (stack_size > UINT_MAX)
223 { 216 {
@@ -226,15 +219,18 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
226 } 219 }
227#endif /* SIZE_MAX != UINT_MAX */ 220#endif /* SIZE_MAX != UINT_MAX */
228 221
229 *thread = (HANDLE) _beginthreadex (NULL, 222 thread->handle = (MHD_thread_handle_)
223 _beginthreadex (NULL,
230 (unsigned int) stack_size, 224 (unsigned int) stack_size,
231 start_routine, 225 start_routine,
232 arg, 226 arg,
233 0, 227 0,
234 NULL); 228 &thread_ID);
235 if ((MHD_thread_handle_)-1 == (*thread)) 229
230 if ((MHD_thread_handle_)-1 == thread->handle)
236 return 0; 231 return 0;
237 232
233 thread->ID = (MHD_thread_ID_)thread_ID;
238 return !0; 234 return !0;
239#endif 235#endif
240} 236}
@@ -294,7 +290,7 @@ named_thread_starter (void *data)
294 * @return non-zero on success; zero otherwise (with errno set) 290 * @return non-zero on success; zero otherwise (with errno set)
295 */ 291 */
296int 292int
297MHD_create_named_thread_ (MHD_thread_handle_ *thread, 293MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread,
298 const char* thread_name, 294 const char* thread_name,
299 size_t stack_size, 295 size_t stack_size,
300 MHD_THREAD_START_ROUTINE_ start_routine, 296 MHD_THREAD_START_ROUTINE_ start_routine,
@@ -323,7 +319,7 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread,
323 res = pthread_attr_setstacksize (&attr, 319 res = pthread_attr_setstacksize (&attr,
324 stack_size); 320 stack_size);
325 if (0 == res) 321 if (0 == res)
326 res = pthread_create (thread, 322 res = pthread_create (&(thread->handle),
327 &attr, 323 &attr,
328 start_routine, 324 start_routine,
329 arg); 325 arg);
diff --git a/src/microhttpd/mhd_threads.h b/src/microhttpd/mhd_threads.h
index 988344b6..49bd77b8 100644
--- a/src/microhttpd/mhd_threads.h
+++ b/src/microhttpd/mhd_threads.h
@@ -86,6 +86,28 @@
86#endif 86#endif
87 87
88#if defined(MHD_USE_POSIX_THREADS) 88#if defined(MHD_USE_POSIX_THREADS)
89 typedef pthread_t MHD_thread_ID_;
90#elif defined(MHD_USE_W32_THREADS)
91 typedef DWORD MHD_thread_ID_;
92#endif
93
94#if defined(MHD_USE_POSIX_THREADS)
95 union _MHD_thread_handle_ID_
96 {
97 MHD_thread_handle_ handle;
98 MHD_thread_ID_ ID;
99 };
100 typedef union _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
101#elif defined(MHD_USE_W32_THREADS)
102 struct _MHD_thread_handle_ID_
103 {
104 MHD_thread_handle_ handle;
105 MHD_thread_ID_ ID;
106 };
107 typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
108#endif
109
110#if defined(MHD_USE_POSIX_THREADS)
89/** 111/**
90 * Wait until specified thread is ended and free thread handle on success. 112 * Wait until specified thread is ended and free thread handle on success.
91 * @param thread handle to watch 113 * @param thread handle to watch
@@ -123,7 +145,7 @@ typedef MHD_THRD_RTRN_TYPE_
123 * @return non-zero on success; zero otherwise 145 * @return non-zero on success; zero otherwise
124 */ 146 */
125int 147int
126MHD_create_thread_ (MHD_thread_handle_ *thread, 148MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
127 size_t stack_size, 149 size_t stack_size,
128 MHD_THREAD_START_ROUTINE_ start_routine, 150 MHD_THREAD_START_ROUTINE_ start_routine,
129 void *arg); 151 void *arg);
@@ -142,7 +164,7 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
142 * @return non-zero on success; zero otherwise 164 * @return non-zero on success; zero otherwise
143 */ 165 */
144int 166int
145MHD_create_named_thread_ (MHD_thread_handle_ *thread, 167MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread,
146 const char* thread_name, 168 const char* thread_name,
147 size_t stack_size, 169 size_t stack_size,
148 MHD_THREAD_START_ROUTINE_ start_routine, 170 MHD_THREAD_START_ROUTINE_ start_routine,