Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 384 lines (334 sloc) 13.916 kb
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
1 /*
e49e2891 » Nick Mathewson
2012-02-10 Update copyright notices to 2012
2 * Copyright (c) 2008-2012 Niels Provos, Nick Mathewson
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
3f8c7cd0 » Nick Mathewson
2012-02-29 Convert include-guard macro convention to avoid reserved identifiers
26 #ifndef EVTHREAD_INTERNAL_H_INCLUDED_
27 #define EVTHREAD_INTERNAL_H_INCLUDED_
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
28
29 #ifdef __cplusplus
838d0a81 » Nick Mathewson
2009-04-17 Document many internal functions and pieces of code.
30 extern "C" {
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
31 #endif
32
ec347b92 » Nick Mathewson
2010-07-07 Move event-config.h to include/event2
33 #include "event2/event-config.h"
0915ca0a » kev009
2011-01-02 Include evconfig-private.h in internal files for great good.
34 #include "evconfig-private.h"
35
36 #include "event2/thread.h"
28255a26 » Nick Mathewson
2009-04-05 Finally, get unit tests to pass with threading turned off again.
37 #include "util-internal.h"
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
38
39 struct event_base;
ec35eb55 » Nick Mathewson
2009-02-12 Make threading functions global, like the mm_ functions. Use the libe…
40
9f560bfa » Nick Mathewson
2011-05-25 Use "_WIN32", not WIN32: it's standard and we don't need to fake it
41 #ifndef _WIN32
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
42 /* On Windows, the way we currently make DLLs, it's not allowed for us to
43 * have shared global structures. Thus, we only do the direct-call-to-function
44 * code path if we know that the local shared library system supports it.
45 */
46 #define EVTHREAD_EXPOSE_STRUCTS
47 #endif
48
68120d9b » Nick Mathewson
2012-02-29 Convert event-config.h macros to avoid reserved identifiers
49 #if ! defined(EVENT__DISABLE_THREAD_SUPPORT) && defined(EVTHREAD_EXPOSE_STRUCTS)
838d0a81 » Nick Mathewson
2009-04-17 Document many internal functions and pieces of code.
50 /* Global function pointers to lock-related functions. NULL if locking isn't
51 enabled. */
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
52 extern struct evthread_lock_callbacks evthread_lock_fns_;
53 extern struct evthread_condition_callbacks evthread_cond_fns_;
54 extern unsigned long (*evthread_id_fn_)(void);
55 extern int evthread_lock_debugging_enabled_;
ec35eb55 » Nick Mathewson
2009-02-12 Make threading functions global, like the mm_ functions. Use the libe…
56
838d0a81 » Nick Mathewson
2009-04-17 Document many internal functions and pieces of code.
57 /** Return the ID of the current thread, or 1 if threading isn't enabled. */
ec35eb55 » Nick Mathewson
2009-02-12 Make threading functions global, like the mm_ functions. Use the libe…
58 #define EVTHREAD_GET_ID() \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
59 (evthread_id_fn_ ? evthread_id_fn_() : 1)
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
60
c7a06bfa » Nick Mathewson
2010-09-08 Avoid needlessly calling evthread_notify_base() when the loop is not …
61 /** Return true iff we're in the thread that is currently (or most recently)
62 * running a given event_base's loop. Requires lock. */
ec35eb55 » Nick Mathewson
2009-02-12 Make threading functions global, like the mm_ functions. Use the libe…
63 #define EVBASE_IN_THREAD(base) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
64 (evthread_id_fn_ == NULL || \
65 (base)->th_owner_id == evthread_id_fn_())
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
66
c7a06bfa » Nick Mathewson
2010-09-08 Avoid needlessly calling evthread_notify_base() when the loop is not …
67 /** Return true iff we need to notify the base's main thread about changes to
68 * its state, because it's currently running the main loop in another
69 * thread. Requires lock. */
70 #define EVBASE_NEED_NOTIFY(base) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
71 (evthread_id_fn_ != NULL && \
c7a06bfa » Nick Mathewson
2010-09-08 Avoid needlessly calling evthread_notify_base() when the loop is not …
72 (base)->running_loop && \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
73 (base)->th_owner_id != evthread_id_fn_())
c7a06bfa » Nick Mathewson
2010-09-08 Avoid needlessly calling evthread_notify_base() when the loop is not …
74
838d0a81 » Nick Mathewson
2009-04-17 Document many internal functions and pieces of code.
75 /** Allocate a new lock, and store it in lockvar, a void*. Sets lockvar to
76 NULL if locking is not enabled. */
347952ff » Nick Mathewson
2009-11-27 Revise the locking API: deprecate the old locking callbacks and add t…
77 #define EVTHREAD_ALLOC_LOCK(lockvar, locktype) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
78 ((lockvar) = evthread_lock_fns_.alloc ? \
79 evthread_lock_fns_.alloc(locktype) : NULL)
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
80
838d0a81 » Nick Mathewson
2009-04-17 Document many internal functions and pieces of code.
81 /** Free a given lock, if it is present and locking is enabled. */
347952ff » Nick Mathewson
2009-11-27 Revise the locking API: deprecate the old locking callbacks and add t…
82 #define EVTHREAD_FREE_LOCK(lockvar, locktype) \
83 do { \
946b5841 » Nick Mathewson
2012-02-29 Clean up lingering _identifiers.
84 void *lock_tmp_ = (lockvar); \
85 if (lock_tmp_ && evthread_lock_fns_.free) \
86 evthread_lock_fns_.free(lock_tmp_, (locktype)); \
70ee390f » Nick Mathewson
2009-04-05 Add some more utility macros to evthread-internal.h
87 } while (0)
88
838d0a81 » Nick Mathewson
2009-04-17 Document many internal functions and pieces of code.
89 /** Acquire a lock. */
347952ff » Nick Mathewson
2009-11-27 Revise the locking API: deprecate the old locking callbacks and add t…
90 #define EVLOCK_LOCK(lockvar,mode) \
70ee390f » Nick Mathewson
2009-04-05 Add some more utility macros to evthread-internal.h
91 do { \
347952ff » Nick Mathewson
2009-11-27 Revise the locking API: deprecate the old locking callbacks and add t…
92 if (lockvar) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
93 evthread_lock_fns_.lock(mode, lockvar); \
70ee390f » Nick Mathewson
2009-04-05 Add some more utility macros to evthread-internal.h
94 } while (0)
838d0a81 » Nick Mathewson
2009-04-17 Document many internal functions and pieces of code.
95
96 /** Release a lock */
347952ff » Nick Mathewson
2009-11-27 Revise the locking API: deprecate the old locking callbacks and add t…
97 #define EVLOCK_UNLOCK(lockvar,mode) \
70ee390f » Nick Mathewson
2009-04-05 Add some more utility macros to evthread-internal.h
98 do { \
347952ff » Nick Mathewson
2009-11-27 Revise the locking API: deprecate the old locking callbacks and add t…
99 if (lockvar) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
100 evthread_lock_fns_.unlock(mode, lockvar); \
70ee390f » Nick Mathewson
2009-04-05 Add some more utility macros to evthread-internal.h
101 } while (0)
838d0a81 » Nick Mathewson
2009-04-17 Document many internal functions and pieces of code.
102
103 /** Helper: put lockvar1 and lockvar2 into pointerwise ascending order. */
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
104 #define EVLOCK_SORTLOCKS_(lockvar1, lockvar2) \
70ee390f » Nick Mathewson
2009-04-05 Add some more utility macros to evthread-internal.h
105 do { \
106 if (lockvar1 && lockvar2 && lockvar1 > lockvar2) { \
107 void *tmp = lockvar1; \
108 lockvar1 = lockvar2; \
109 lockvar2 = tmp; \
110 } \
111 } while (0)
112
838d0a81 » Nick Mathewson
2009-04-17 Document many internal functions and pieces of code.
113 /** Lock an event_base, if it is set up for locking. Acquires the lock
76cd2b70 » Nick Mathewson
2009-11-27 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
114 in the base structure whose field is named 'lockvar'. */
115 #define EVBASE_ACQUIRE_LOCK(base, lockvar) do { \
218a3c37 » Nick Mathewson
2010-05-13 Do not check that event_base is set in EVBASE_ACQUIRE_LOCK
116 EVLOCK_LOCK((base)->lockvar, 0); \
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
117 } while (0)
118
838d0a81 » Nick Mathewson
2009-04-17 Document many internal functions and pieces of code.
119 /** Unlock an event_base, if it is set up for locking. */
76cd2b70 » Nick Mathewson
2009-11-27 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
120 #define EVBASE_RELEASE_LOCK(base, lockvar) do { \
218a3c37 » Nick Mathewson
2010-05-13 Do not check that event_base is set in EVBASE_ACQUIRE_LOCK
121 EVLOCK_UNLOCK((base)->lockvar, 0); \
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
122 } while (0)
0cd3bb9f » Nick Mathewson
2009-11-27 Improved optional lock debugging.
123
124 /** If lock debugging is enabled, and lock is non-null, assert that 'lock' is
125 * locked and held by us. */
126 #define EVLOCK_ASSERT_LOCKED(lock) \
127 do { \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
128 if ((lock) && evthread_lock_debugging_enabled_) { \
129 EVUTIL_ASSERT(evthread_is_debug_lock_held_(lock)); \
0cd3bb9f » Nick Mathewson
2009-11-27 Improved optional lock debugging.
130 } \
131 } while (0)
132
689fc091 » Nick Mathewson
2009-11-28 New EVTHREAD_TRY_LOCK function to try to grab a lock.
133 /** Try to grab the lock for 'lockvar' without blocking, and return 1 if we
134 * manage to get it. */
8ac3c4c2 » Nick Mathewson
2012-02-29 Have all visible internal function names end with an underscore.
135 static inline int EVLOCK_TRY_LOCK_(void *lock);
689fc091 » Nick Mathewson
2009-11-28 New EVTHREAD_TRY_LOCK function to try to grab a lock.
136 static inline int
8ac3c4c2 » Nick Mathewson
2012-02-29 Have all visible internal function names end with an underscore.
137 EVLOCK_TRY_LOCK_(void *lock)
689fc091 » Nick Mathewson
2009-11-28 New EVTHREAD_TRY_LOCK function to try to grab a lock.
138 {
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
139 if (lock && evthread_lock_fns_.lock) {
140 int r = evthread_lock_fns_.lock(EVTHREAD_TRY, lock);
689fc091 » Nick Mathewson
2009-11-28 New EVTHREAD_TRY_LOCK function to try to grab a lock.
141 return !r;
142 } else {
143 /* Locking is disabled either globally or for this thing;
144 * of course we count as having the lock. */
145 return 1;
146 }
147 }
148
d4977b52 » Nick Mathewson
2010-08-17 Add a condition variable backend, with implementations for pthreads a…
149 /** Allocate a new condition variable and store it in the void *, condvar */
150 #define EVTHREAD_ALLOC_COND(condvar) \
151 do { \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
152 (condvar) = evthread_cond_fns_.alloc_condition ? \
153 evthread_cond_fns_.alloc_condition(0) : NULL; \
d4977b52 » Nick Mathewson
2010-08-17 Add a condition variable backend, with implementations for pthreads a…
154 } while (0)
155 /** Deallocate and free a condition variable in condvar */
156 #define EVTHREAD_FREE_COND(cond) \
157 do { \
158 if (cond) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
159 evthread_cond_fns_.free_condition((cond)); \
d4977b52 » Nick Mathewson
2010-08-17 Add a condition variable backend, with implementations for pthreads a…
160 } while (0)
161 /** Signal one thread waiting on cond */
162 #define EVTHREAD_COND_SIGNAL(cond) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
163 ( (cond) ? evthread_cond_fns_.signal_condition((cond), 0) : 0 )
d4977b52 » Nick Mathewson
2010-08-17 Add a condition variable backend, with implementations for pthreads a…
164 /** Signal all threads waiting on cond */
165 #define EVTHREAD_COND_BROADCAST(cond) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
166 ( (cond) ? evthread_cond_fns_.signal_condition((cond), 1) : 0 )
d4977b52 » Nick Mathewson
2010-08-17 Add a condition variable backend, with implementations for pthreads a…
167 /** Wait until the condition 'cond' is signalled. Must be called while
168 * holding 'lock'. The lock will be released until the condition is
169 * signalled, at which point it will be acquired again. Returns 0 for
170 * success, -1 for failure. */
171 #define EVTHREAD_COND_WAIT(cond, lock) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
172 ( (cond) ? evthread_cond_fns_.wait_condition((cond), (lock), NULL) : 0 )
d4977b52 » Nick Mathewson
2010-08-17 Add a condition variable backend, with implementations for pthreads a…
173 /** As EVTHREAD_COND_WAIT, but gives up after 'tv' has elapsed. Returns 1
174 * on timeout. */
175 #define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
176 ( (cond) ? evthread_cond_fns_.wait_condition((cond), (lock), (tv)) : 0 )
d4977b52 » Nick Mathewson
2010-08-17 Add a condition variable backend, with implementations for pthreads a…
177
e7874133 » Nick Mathewson
2011-11-14 Don't try to make notifiable event_base when no threading fns are con…
178 /** True iff locking functions have been configured. */
179 #define EVTHREAD_LOCKING_ENABLED() \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
180 (evthread_lock_fns_.lock != NULL)
e7874133 » Nick Mathewson
2011-11-14 Don't try to make notifiable event_base when no threading fns are con…
181
68120d9b » Nick Mathewson
2012-02-29 Convert event-config.h macros to avoid reserved identifiers
182 #elif ! defined(EVENT__DISABLE_THREAD_SUPPORT)
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
183
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
184 unsigned long evthreadimpl_get_id_(void);
185 int evthreadimpl_is_lock_debugging_enabled_(void);
186 void *evthreadimpl_lock_alloc_(unsigned locktype);
187 void evthreadimpl_lock_free_(void *lock, unsigned locktype);
188 int evthreadimpl_lock_lock_(unsigned mode, void *lock);
189 int evthreadimpl_lock_unlock_(unsigned mode, void *lock);
190 void *evthreadimpl_cond_alloc_(unsigned condtype);
191 void evthreadimpl_cond_free_(void *cond);
192 int evthreadimpl_cond_signal_(void *cond, int broadcast);
193 int evthreadimpl_cond_wait_(void *cond, void *lock, const struct timeval *tv);
194 int evthreadimpl_locking_enabled_(void);
195
196 #define EVTHREAD_GET_ID() evthreadimpl_get_id_()
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
197 #define EVBASE_IN_THREAD(base) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
198 ((base)->th_owner_id == evthreadimpl_get_id_())
e7dc501e » Nick Mathewson
2010-09-08 Implement EVBASE_NEED_NOTIFY on win32
199 #define EVBASE_NEED_NOTIFY(base) \
200 ((base)->running_loop && \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
201 ((base)->th_owner_id != evthreadimpl_get_id_()))
e7dc501e » Nick Mathewson
2010-09-08 Implement EVBASE_NEED_NOTIFY on win32
202
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
203 #define EVTHREAD_ALLOC_LOCK(lockvar, locktype) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
204 ((lockvar) = evthreadimpl_lock_alloc_(locktype))
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
205
206 #define EVTHREAD_FREE_LOCK(lockvar, locktype) \
207 do { \
946b5841 » Nick Mathewson
2012-02-29 Clean up lingering _identifiers.
208 void *lock_tmp_ = (lockvar); \
209 if (lock_tmp_) \
210 evthreadimpl_lock_free_(lock_tmp_, (locktype)); \
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
211 } while (0)
212
213 /** Acquire a lock. */
214 #define EVLOCK_LOCK(lockvar,mode) \
215 do { \
216 if (lockvar) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
217 evthreadimpl_lock_lock_(mode, lockvar); \
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
218 } while (0)
219
220 /** Release a lock */
221 #define EVLOCK_UNLOCK(lockvar,mode) \
222 do { \
223 if (lockvar) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
224 evthreadimpl_lock_unlock_(mode, lockvar); \
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
225 } while (0)
226
227 /** Lock an event_base, if it is set up for locking. Acquires the lock
228 in the base structure whose field is named 'lockvar'. */
229 #define EVBASE_ACQUIRE_LOCK(base, lockvar) do { \
230 EVLOCK_LOCK((base)->lockvar, 0); \
231 } while (0)
232
233 /** Unlock an event_base, if it is set up for locking. */
234 #define EVBASE_RELEASE_LOCK(base, lockvar) do { \
235 EVLOCK_UNLOCK((base)->lockvar, 0); \
236 } while (0)
237
238 /** If lock debugging is enabled, and lock is non-null, assert that 'lock' is
239 * locked and held by us. */
240 #define EVLOCK_ASSERT_LOCKED(lock) \
241 do { \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
242 if ((lock) && evthreadimpl_is_lock_debugging_enabled_()) { \
243 EVUTIL_ASSERT(evthread_is_debug_lock_held_(lock)); \
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
244 } \
245 } while (0)
246
247 /** Try to grab the lock for 'lockvar' without blocking, and return 1 if we
248 * manage to get it. */
8ac3c4c2 » Nick Mathewson
2012-02-29 Have all visible internal function names end with an underscore.
249 static inline int EVLOCK_TRY_LOCK_(void *lock);
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
250 static inline int
8ac3c4c2 » Nick Mathewson
2012-02-29 Have all visible internal function names end with an underscore.
251 EVLOCK_TRY_LOCK_(void *lock)
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
252 {
253 if (lock) {
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
254 int r = evthreadimpl_lock_lock_(EVTHREAD_TRY, lock);
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
255 return !r;
256 } else {
257 /* Locking is disabled either globally or for this thing;
258 * of course we count as having the lock. */
259 return 1;
260 }
261 }
262
263 /** Allocate a new condition variable and store it in the void *, condvar */
264 #define EVTHREAD_ALLOC_COND(condvar) \
265 do { \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
266 (condvar) = evthreadimpl_cond_alloc_(0); \
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
267 } while (0)
268 /** Deallocate and free a condition variable in condvar */
269 #define EVTHREAD_FREE_COND(cond) \
270 do { \
271 if (cond) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
272 evthreadimpl_cond_free_((cond)); \
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
273 } while (0)
274 /** Signal one thread waiting on cond */
275 #define EVTHREAD_COND_SIGNAL(cond) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
276 ( (cond) ? evthreadimpl_cond_signal_((cond), 0) : 0 )
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
277 /** Signal all threads waiting on cond */
278 #define EVTHREAD_COND_BROADCAST(cond) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
279 ( (cond) ? evthreadimpl_cond_signal_((cond), 1) : 0 )
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
280 /** Wait until the condition 'cond' is signalled. Must be called while
281 * holding 'lock'. The lock will be released until the condition is
282 * signalled, at which point it will be acquired again. Returns 0 for
283 * success, -1 for failure. */
284 #define EVTHREAD_COND_WAIT(cond, lock) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
285 ( (cond) ? evthreadimpl_cond_wait_((cond), (lock), NULL) : 0 )
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
286 /** As EVTHREAD_COND_WAIT, but gives up after 'tv' has elapsed. Returns 1
287 * on timeout. */
288 #define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
289 ( (cond) ? evthreadimpl_cond_wait_((cond), (lock), (tv)) : 0 )
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
290
e7874133 » Nick Mathewson
2011-11-14 Don't try to make notifiable event_base when no threading fns are con…
291 #define EVTHREAD_LOCKING_ENABLED() \
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
292 (evthreadimpl_locking_enabled_())
e7874133 » Nick Mathewson
2011-11-14 Don't try to make notifiable event_base when no threading fns are con…
293
68120d9b » Nick Mathewson
2012-02-29 Convert event-config.h macros to avoid reserved identifiers
294 #else /* EVENT__DISABLE_THREAD_SUPPORT */
d13b59ce » Nick Mathewson
2009-04-05 Fix build with thread support disabled, and make no-op macros a littl…
295
ec35eb55 » Nick Mathewson
2009-02-12 Make threading functions global, like the mm_ functions. Use the libe…
296 #define EVTHREAD_GET_ID() 1
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
297 #define EVTHREAD_ALLOC_LOCK(lockvar, locktype) EVUTIL_NIL_STMT_
298 #define EVTHREAD_FREE_LOCK(lockvar, locktype) EVUTIL_NIL_STMT_
d13b59ce » Nick Mathewson
2009-04-05 Fix build with thread support disabled, and make no-op macros a littl…
299
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
300 #define EVLOCK_LOCK(lockvar, mode) EVUTIL_NIL_STMT_
301 #define EVLOCK_UNLOCK(lockvar, mode) EVUTIL_NIL_STMT_
302 #define EVLOCK_LOCK2(lock1,lock2,mode1,mode2) EVUTIL_NIL_STMT_
303 #define EVLOCK_UNLOCK2(lock1,lock2,mode1,mode2) EVUTIL_NIL_STMT_
d13b59ce » Nick Mathewson
2009-04-05 Fix build with thread support disabled, and make no-op macros a littl…
304
305 #define EVBASE_IN_THREAD(base) 1
c7a06bfa » Nick Mathewson
2010-09-08 Avoid needlessly calling evthread_notify_base() when the loop is not …
306 #define EVBASE_NEED_NOTIFY(base) 0
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
307 #define EVBASE_ACQUIRE_LOCK(base, lock) EVUTIL_NIL_STMT_
308 #define EVBASE_RELEASE_LOCK(base, lock) EVUTIL_NIL_STMT_
309 #define EVLOCK_ASSERT_LOCKED(lock) EVUTIL_NIL_STMT_
689fc091 » Nick Mathewson
2009-11-28 New EVTHREAD_TRY_LOCK function to try to grab a lock.
310
8ac3c4c2 » Nick Mathewson
2012-02-29 Have all visible internal function names end with an underscore.
311 #define EVLOCK_TRY_LOCK_(lock) 1
d4977b52 » Nick Mathewson
2010-08-17 Add a condition variable backend, with implementations for pthreads a…
312
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
313 #define EVTHREAD_ALLOC_COND(condvar) EVUTIL_NIL_STMT_
314 #define EVTHREAD_FREE_COND(cond) EVUTIL_NIL_STMT_
315 #define EVTHREAD_COND_SIGNAL(cond) EVUTIL_NIL_STMT_
316 #define EVTHREAD_COND_BROADCAST(cond) EVUTIL_NIL_STMT_
317 #define EVTHREAD_COND_WAIT(cond, lock) EVUTIL_NIL_STMT_
318 #define EVTHREAD_COND_WAIT_TIMED(cond, lock, howlong) EVUTIL_NIL_STMT_
d4977b52 » Nick Mathewson
2010-08-17 Add a condition variable backend, with implementations for pthreads a…
319
e7874133 » Nick Mathewson
2011-11-14 Don't try to make notifiable event_base when no threading fns are con…
320 #define EVTHREAD_LOCKING_ENABLED() 0
321
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
322 #endif
323
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
324 /* This code is shared between both lock impls */
68120d9b » Nick Mathewson
2012-02-29 Convert event-config.h macros to avoid reserved identifiers
325 #if ! defined(EVENT__DISABLE_THREAD_SUPPORT)
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
326 /** Helper: put lockvar1 and lockvar2 into pointerwise ascending order. */
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
327 #define EVLOCK_SORTLOCKS_(lockvar1, lockvar2) \
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
328 do { \
329 if (lockvar1 && lockvar2 && lockvar1 > lockvar2) { \
330 void *tmp = lockvar1; \
331 lockvar1 = lockvar2; \
332 lockvar2 = tmp; \
333 } \
334 } while (0)
335
336 /** Acquire both lock1 and lock2. Always allocates locks in the same order,
337 * so that two threads locking two locks with LOCK2 will not deadlock. */
338 #define EVLOCK_LOCK2(lock1,lock2,mode1,mode2) \
339 do { \
946b5841 » Nick Mathewson
2012-02-29 Clean up lingering _identifiers.
340 void *lock1_tmplock_ = (lock1); \
341 void *lock2_tmplock_ = (lock2); \
342 EVLOCK_SORTLOCKS_(lock1_tmplock_,lock2_tmplock_); \
343 EVLOCK_LOCK(lock1_tmplock_,mode1); \
344 if (lock2_tmplock_ != lock1_tmplock_) \
345 EVLOCK_LOCK(lock2_tmplock_,mode2); \
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
346 } while (0)
347 /** Release both lock1 and lock2. */
348 #define EVLOCK_UNLOCK2(lock1,lock2,mode1,mode2) \
349 do { \
946b5841 » Nick Mathewson
2012-02-29 Clean up lingering _identifiers.
350 void *lock1_tmplock_ = (lock1); \
351 void *lock2_tmplock_ = (lock2); \
352 EVLOCK_SORTLOCKS_(lock1_tmplock_,lock2_tmplock_); \
353 if (lock2_tmplock_ != lock1_tmplock_) \
354 EVLOCK_UNLOCK(lock2_tmplock_,mode2); \
355 EVLOCK_UNLOCK(lock1_tmplock_,mode1); \
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
356 } while (0)
357
cb9da0bf » Nick Mathewson
2012-02-29 Fix all identifiers with names beginning with underscore.
358 int evthread_is_debug_lock_held_(void *lock);
359 void *evthread_debug_get_real_lock_(void *lock);
b683cae3 » Nick Mathewson
2011-04-22 Avoid race-condition when initializing global locks
360
361 void *evthread_setup_global_lock_(void *lock_, unsigned locktype,
362 int enable_locks);
363
364 #define EVTHREAD_SETUP_GLOBAL_LOCK(lockvar, locktype) \
365 do { \
366 lockvar = evthread_setup_global_lock_(lockvar, \
367 (locktype), enable_locks); \
368 if (!lockvar) { \
369 event_warn("Couldn't allocate %s", #lockvar); \
370 return -1; \
371 } \
372 } while (0);
373
374 int event_global_setup_locks_(const int enable_locks);
375 int evsig_global_setup_locks_(const int enable_locks);
376 int evutil_secure_rng_global_setup_locks_(const int enable_locks);
377
5de2bcb7 » Nick Mathewson
2010-09-01 On windows, make lock/thread function tables static
378 #endif
379
558de9b3 » provos
2008-03-02 Provide OpenSSL style support for multiple threads accessing the same…
380 #ifdef __cplusplus
381 }
382 #endif
383
3f8c7cd0 » Nick Mathewson
2012-02-29 Convert include-guard macro convention to avoid reserved identifiers
384 #endif /* EVTHREAD_INTERNAL_H_INCLUDED_ */
Something went wrong with that request. Please try again.