aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_threads.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_threads.h')
-rw-r--r--src/microhttpd/mhd_threads.h78
1 files changed, 43 insertions, 35 deletions
diff --git a/src/microhttpd/mhd_threads.h b/src/microhttpd/mhd_threads.h
index 6d69b9ed..79520d53 100644
--- a/src/microhttpd/mhd_threads.h
+++ b/src/microhttpd/mhd_threads.h
@@ -58,23 +58,26 @@
58 58
59#ifndef MHD_NO_THREAD_NAMES 59#ifndef MHD_NO_THREAD_NAMES
60# if defined(MHD_USE_POSIX_THREADS) 60# if defined(MHD_USE_POSIX_THREADS)
61# if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || \ 61# if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || \
62 defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) || \ 62 defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || \
63 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) 63 defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || \
64 defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) || \
65 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || \
66 defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
64# define MHD_USE_THREAD_NAME_ 67# define MHD_USE_THREAD_NAME_
65# endif /* HAVE_PTHREAD_SETNAME_NP */ 68# endif /* HAVE_PTHREAD_SETNAME_NP */
66# elif defined(MHD_USE_W32_THREADS) 69# elif defined(MHD_USE_W32_THREADS)
67# ifdef _MSC_FULL_VER 70# ifdef _MSC_FULL_VER
68 /* Thread names only available with VC compiler */ 71/* Thread names only available with VC compiler */
69# define MHD_USE_THREAD_NAME_ 72# define MHD_USE_THREAD_NAME_
70# endif /* _MSC_FULL_VER */ 73# endif /* _MSC_FULL_VER */
71# endif 74# endif
72#endif 75#endif
73 76
74#if defined(MHD_USE_POSIX_THREADS) 77#if defined(MHD_USE_POSIX_THREADS)
75 typedef pthread_t MHD_thread_handle_; 78typedef pthread_t MHD_thread_handle_;
76#elif defined(MHD_USE_W32_THREADS) 79#elif defined(MHD_USE_W32_THREADS)
77 typedef HANDLE MHD_thread_handle_; 80typedef HANDLE MHD_thread_handle_;
78#endif 81#endif
79 82
80#if defined(MHD_USE_POSIX_THREADS) 83#if defined(MHD_USE_POSIX_THREADS)
@@ -86,9 +89,9 @@
86#endif 89#endif
87 90
88#if defined(MHD_USE_POSIX_THREADS) 91#if defined(MHD_USE_POSIX_THREADS)
89 typedef pthread_t MHD_thread_ID_; 92typedef pthread_t MHD_thread_ID_;
90#elif defined(MHD_USE_W32_THREADS) 93#elif defined(MHD_USE_W32_THREADS)
91 typedef DWORD MHD_thread_ID_; 94typedef DWORD MHD_thread_ID_;
92#endif 95#endif
93 96
94/* Depending on implementation, pthread_create() MAY set thread ID into 97/* Depending on implementation, pthread_create() MAY set thread ID into
@@ -100,27 +103,27 @@
100 * to save some resources. */ 103 * to save some resources. */
101#if defined(MHD_USE_POSIX_THREADS) 104#if defined(MHD_USE_POSIX_THREADS)
102# ifdef MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD 105# ifdef MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD
103 union _MHD_thread_handle_ID_ 106union _MHD_thread_handle_ID_
104 { 107{
105 MHD_thread_handle_ handle; /**< To be used in other threads */ 108 MHD_thread_handle_ handle; /**< To be used in other threads */
106 MHD_thread_ID_ ID; /**< To be used in thread itself */ 109 MHD_thread_ID_ ID; /**< To be used in thread itself */
107 }; 110};
108 typedef union _MHD_thread_handle_ID_ MHD_thread_handle_ID_; 111typedef union _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
109# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 112# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
110 struct _MHD_thread_handle_ID_ 113struct _MHD_thread_handle_ID_
111 { 114{
112 MHD_thread_handle_ handle; /**< To be used in other threads */ 115 MHD_thread_handle_ handle; /**< To be used in other threads */
113 MHD_thread_ID_ ID; /**< To be used in thread itself */ 116 MHD_thread_ID_ ID; /**< To be used in thread itself */
114 }; 117};
115 typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_; 118typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
116# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 119# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
117#elif defined(MHD_USE_W32_THREADS) 120#elif defined(MHD_USE_W32_THREADS)
118 struct _MHD_thread_handle_ID_ 121struct _MHD_thread_handle_ID_
119 { 122{
120 MHD_thread_handle_ handle; /**< To be used in other threads */ 123 MHD_thread_handle_ handle; /**< To be used in other threads */
121 MHD_thread_ID_ ID; /**< To be used in thread itself */ 124 MHD_thread_ID_ ID; /**< To be used in thread itself */
122 }; 125};
123 typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_; 126typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
124#endif 127#endif
125 128
126#if defined(MHD_USE_POSIX_THREADS) 129#if defined(MHD_USE_POSIX_THREADS)
@@ -129,14 +132,17 @@
129 * @param thread handle to watch 132 * @param thread handle to watch
130 * @return nonzero on success, zero otherwise 133 * @return nonzero on success, zero otherwise
131 */ 134 */
132#define MHD_join_thread_(thread) (!pthread_join((thread), NULL)) 135#define MHD_join_thread_(thread) (! pthread_join ((thread), NULL))
133#elif defined(MHD_USE_W32_THREADS) 136#elif defined(MHD_USE_W32_THREADS)
134/** 137/**
135 * Wait until specified thread is ended and free thread handle on success. 138 * Wait until specified thread is ended and free thread handle on success.
136 * @param thread handle to watch 139 * @param thread handle to watch
137 * @return nonzero on success, zero otherwise 140 * @return nonzero on success, zero otherwise
138 */ 141 */
139#define MHD_join_thread_(thread) (WAIT_OBJECT_0 == WaitForSingleObject((thread), INFINITE) ? (CloseHandle((thread)), !0) : 0) 142#define MHD_join_thread_(thread) (WAIT_OBJECT_0 == WaitForSingleObject ( \
143 (thread), INFINITE) ? (CloseHandle ( \
144 (thread)), ! 0) : \
145 0)
140#endif 146#endif
141 147
142#if defined(MHD_USE_POSIX_THREADS) 148#if defined(MHD_USE_POSIX_THREADS)
@@ -145,14 +151,14 @@
145 * @param ID thread ID to match 151 * @param ID thread ID to match
146 * @return nonzero on match, zero otherwise 152 * @return nonzero on match, zero otherwise
147 */ 153 */
148#define MHD_thread_ID_match_current_(ID) (pthread_equal((ID), pthread_self())) 154#define MHD_thread_ID_match_current_(ID) (pthread_equal ((ID), pthread_self ()))
149#elif defined(MHD_USE_W32_THREADS) 155#elif defined(MHD_USE_W32_THREADS)
150/** 156/**
151 * Check whether provided thread ID match current thread. 157 * Check whether provided thread ID match current thread.
152 * @param ID thread ID to match 158 * @param ID thread ID to match
153 * @return nonzero on match, zero otherwise 159 * @return nonzero on match, zero otherwise
154 */ 160 */
155#define MHD_thread_ID_match_current_(ID) (GetCurrentThreadId() == (ID)) 161#define MHD_thread_ID_match_current_(ID) (GetCurrentThreadId () == (ID))
156#endif 162#endif
157 163
158#if defined(MHD_USE_POSIX_THREADS) 164#if defined(MHD_USE_POSIX_THREADS)
@@ -161,20 +167,22 @@
161 * Initialise thread ID. 167 * Initialise thread ID.
162 * @param thread_handle_ID_ptr pointer to thread handle-ID 168 * @param thread_handle_ID_ptr pointer to thread handle-ID
163 */ 169 */
164#define MHD_thread_init_(thread_handle_ID_ptr) (void)0 170#define MHD_thread_init_(thread_handle_ID_ptr) (void) 0
165# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 171# else /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
166/** 172/**
167 * Initialise thread ID. 173 * Initialise thread ID.
168 * @param thread_handle_ID_ptr pointer to thread handle-ID 174 * @param thread_handle_ID_ptr pointer to thread handle-ID
169 */ 175 */
170#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID=pthread_self()) 176#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID = \
177 pthread_self ())
171# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */ 178# endif /* ! MHD_PTHREAD_CREATE__SET_ID_BEFORE_START_THREAD */
172#elif defined(MHD_USE_W32_THREADS) 179#elif defined(MHD_USE_W32_THREADS)
173/** 180/**
174 * Initialise thread ID. 181 * Initialise thread ID.
175 * @param thread_handle_ID_ptr pointer to thread handle-ID 182 * @param thread_handle_ID_ptr pointer to thread handle-ID
176 */ 183 */
177#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID=GetCurrentThreadId()) 184#define MHD_thread_init_(thread_handle_ID_ptr) ((thread_handle_ID_ptr)->ID = \
185 GetCurrentThreadId ())
178#endif 186#endif
179 187
180/** 188/**
@@ -205,7 +213,7 @@ MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
205 void *arg); 213 void *arg);
206 214
207#ifndef MHD_USE_THREAD_NAME_ 215#ifndef MHD_USE_THREAD_NAME_
208#define MHD_create_named_thread_(t,n,s,r,a) MHD_create_thread_((t),(s),(r),(a)) 216#define MHD_create_named_thread_(t,n,s,r,a) MHD_create_thread_ ((t),(s),(r),(a))
209#else /* MHD_USE_THREAD_NAME_ */ 217#else /* MHD_USE_THREAD_NAME_ */
210/** 218/**
211 * Create a named thread and set the attributes according to our options. 219 * Create a named thread and set the attributes according to our options.
@@ -219,7 +227,7 @@ MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
219 */ 227 */
220int 228int
221MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread, 229MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread,
222 const char* thread_name, 230 const char*thread_name,
223 size_t stack_size, 231 size_t stack_size,
224 MHD_THREAD_START_ROUTINE_ start_routine, 232 MHD_THREAD_START_ROUTINE_ start_routine,
225 void *arg); 233 void *arg);