Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 137 lines (115 sloc) 4.755 kb
558de9b @provos Provide OpenSSL style support for multiple threads accessing the same ev...
provos authored
1 /*
2 * Copyright (c) 2008 Niels Provos <provos@citi.umich.edu>
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 */
26 #ifndef _EVTHREAD_INTERNAL_H_
27 #define _EVTHREAD_INTERNAL_H_
28
29 #ifdef __cplusplus
ec35eb5 Make threading functions global, like the mm_ functions. Use the libeve...
Nick Mathewson authored
30 //extern "C" {
558de9b @provos Provide OpenSSL style support for multiple threads accessing the same ev...
provos authored
31 #endif
32
8889a77 Replace all use of config.h with event-config.h.
Nick Mathewson authored
33 #include "event-config.h"
28255a2 Finally, get unit tests to pass with threading turned off again.
Nick Mathewson authored
34 #include "util-internal.h"
558de9b @provos Provide OpenSSL style support for multiple threads accessing the same ev...
provos authored
35
36 struct event_base;
ec35eb5 Make threading functions global, like the mm_ functions. Use the libeve...
Nick Mathewson authored
37
8889a77 Replace all use of config.h with event-config.h.
Nick Mathewson authored
38 #ifndef _EVENT_DISABLE_THREAD_SUPPORT
ec35eb5 Make threading functions global, like the mm_ functions. Use the libeve...
Nick Mathewson authored
39 extern void (*_evthread_locking_fn)(int mode, void *lock);
40 extern unsigned long (*_evthread_id_fn)(void);
41 extern void *(*_evthread_lock_alloc_fn)(void);
42 extern void (*_evthread_lock_free_fn)(void *);
43
44 #define EVBASE_USING_LOCKS(base) \
45 (base != NULL && (base)->th_base_lock != NULL)
46
47 #define EVTHREAD_GET_ID() \
48 (_evthread_id_fn ? _evthread_id_fn() : 1)
558de9b @provos Provide OpenSSL style support for multiple threads accessing the same ev...
provos authored
49
ec35eb5 Make threading functions global, like the mm_ functions. Use the libeve...
Nick Mathewson authored
50 #define EVBASE_IN_THREAD(base) \
51 (_evthread_id_fn == NULL || \
52 (base)->th_owner_id == _evthread_id_fn())
558de9b @provos Provide OpenSSL style support for multiple threads accessing the same ev...
provos authored
53
ec35eb5 Make threading functions global, like the mm_ functions. Use the libeve...
Nick Mathewson authored
54 #define EVTHREAD_ALLOC_LOCK(lockvar) \
55 ((lockvar) = _evthread_lock_alloc_fn ? \
56 _evthread_lock_alloc_fn() : NULL)
558de9b @provos Provide OpenSSL style support for multiple threads accessing the same ev...
provos authored
57
ec35eb5 Make threading functions global, like the mm_ functions. Use the libeve...
Nick Mathewson authored
58 #define EVTHREAD_FREE_LOCK(lockvar) \
59 do { \
60 if (lockvar && _evthread_lock_free_fn) \
61 _evthread_lock_free_fn(lockvar); \
70ee390 Add some more utility macros to evthread-internal.h
Nick Mathewson authored
62 } while (0)
63
64 #define EVLOCK_LOCK(lock,mode) \
65 do { \
66 if (lock) \
67 _evthread_locking_fn(EVTHREAD_LOCK|mode, lock); \
68 } while (0)
69 #define EVLOCK_UNLOCK(lock,mode) \
70 do { \
71 if (lock) \
72 _evthread_locking_fn(EVTHREAD_UNLOCK|mode, lock); \
73 } while (0)
74 #define _EVLOCK_SORTLOCKS(lockvar1, lockvar2) \
75 do { \
76 if (lockvar1 && lockvar2 && lockvar1 > lockvar2) { \
77 void *tmp = lockvar1; \
78 lockvar1 = lockvar2; \
79 lockvar2 = tmp; \
80 } \
81 } while (0)
82
83 #define EVLOCK_LOCK2(lock1,lock2,mode1,mode2) \
84 do { \
85 void *_lock1_tmplock = (lock1); \
86 void *_lock2_tmplock = (lock2); \
87 _EVLOCK_SORTLOCKS(_lock1_tmplock,_lock2_tmplock); \
88 EVLOCK_LOCK(_lock1_tmplock,mode1); \
89 if (_lock2_tmplock != _lock1_tmplock) \
90 EVLOCK_LOCK(_lock2_tmplock,mode2); \
91 } while (0)
92
93 #define EVLOCK_UNLOCK2(lock1,lock2,mode1,mode2) \
94 do { \
95 void *_lock1_tmplock = (lock1); \
96 void *_lock2_tmplock = (lock2); \
97 _EVLOCK_SORTLOCKS(_lock1_tmplock,_lock2_tmplock); \
98 if (_lock2_tmplock != _lock1_tmplock) \
99 EVLOCK_UNLOCK(_lock2_tmplock,mode2); \
100 EVLOCK_UNLOCK(_lock1_tmplock,mode1); \
101 } while (0)
102
ec35eb5 Make threading functions global, like the mm_ functions. Use the libeve...
Nick Mathewson authored
103
104 #define EVBASE_ACQUIRE_LOCK(base, mode, lock) do { \
105 if (EVBASE_USING_LOCKS(base)) \
106 _evthread_locking_fn(EVTHREAD_LOCK | mode, \
107 (base)->lock); \
558de9b @provos Provide OpenSSL style support for multiple threads accessing the same ev...
provos authored
108 } while (0)
109
ec35eb5 Make threading functions global, like the mm_ functions. Use the libeve...
Nick Mathewson authored
110 #define EVBASE_RELEASE_LOCK(base, mode, lock) do { \
111 if (EVBASE_USING_LOCKS(base)) \
112 _evthread_locking_fn(EVTHREAD_UNLOCK | mode, \
113 (base)->lock); \
558de9b @provos Provide OpenSSL style support for multiple threads accessing the same ev...
provos authored
114 } while (0)
8889a77 Replace all use of config.h with event-config.h.
Nick Mathewson authored
115 #else /* _EVENT_DISABLE_THREAD_SUPPORT */
d13b59c Fix build with thread support disabled, and make no-op macros a little m...
Nick Mathewson authored
116
ec35eb5 Make threading functions global, like the mm_ functions. Use the libeve...
Nick Mathewson authored
117 #define EVTHREAD_GET_ID() 1
661b5ee Actually, move EVUTIL_NIL_STMT to util-internal.h
Nick Mathewson authored
118 #define EVTHREAD_ALLOC_LOCK(lockvar) _EVUTIL_NIL_STMT
119 #define EVTHREAD_FREE_LOCK(lockvar) _EVUTIL_NIL_STMT
d13b59c Fix build with thread support disabled, and make no-op macros a little m...
Nick Mathewson authored
120
661b5ee Actually, move EVUTIL_NIL_STMT to util-internal.h
Nick Mathewson authored
121 #define EVLOCK_LOCK(lockvar, mode) _EVUTIL_NIL_STMT
122 #define EVLOCK_UNLOCK(lockvar, mode) _EVUTIL_NIL_STMT
123 #define EVLOCK_LOCK2(lock1,lock2,mode1,mode2) _EVUTIL_NIL_STMT
124 #define EVLOCK_UNLOCK2(lock1,lock2,mode1,mode2) _EVUTIL_NIL_STMT
d13b59c Fix build with thread support disabled, and make no-op macros a little m...
Nick Mathewson authored
125
126 #define EVBASE_IN_THREAD(base) 1
661b5ee Actually, move EVUTIL_NIL_STMT to util-internal.h
Nick Mathewson authored
127 #define EVBASE_ACQUIRE_LOCK(base, mode, lock) _EVUTIL_NIL_STMT
128 #define EVBASE_RELEASE_LOCK(base, mode, lock) _EVUTIL_NIL_STMT
ec35eb5 Make threading functions global, like the mm_ functions. Use the libeve...
Nick Mathewson authored
129
558de9b @provos Provide OpenSSL style support for multiple threads accessing the same ev...
provos authored
130 #endif
131
132 #ifdef __cplusplus
133 }
134 #endif
135
136 #endif /* _EVTHREAD_INTERNAL_H_ */
Something went wrong with that request. Please try again.