libevent  2.2.1
Event notification library
thread.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2012 Niels Provos and Nick Mathewson
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 EVENT2_THREAD_H_INCLUDED_
27 #define EVENT2_THREAD_H_INCLUDED_
28 
49 #include <event2/visibility.h>
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 #include <event2/event-config.h>
56 
64 #define EVTHREAD_WRITE 0x04
65 
67 #define EVTHREAD_READ 0x08
68 
71 #define EVTHREAD_TRY 0x10
72 
74 #if !defined(EVENT__DISABLE_THREAD_SUPPORT) || defined(EVENT_IN_DOXYGEN_)
75 
76 #define EVTHREAD_LOCK_API_VERSION 1
77 
85 #define EVTHREAD_LOCKTYPE_RECURSIVE 1
86 /* A read-write lock is one that allows multiple simultaneous readers, but
87  * where any one writer excludes all other writers and readers. */
88 #define EVTHREAD_LOCKTYPE_READWRITE 2
89 
109  void *(*alloc)(unsigned locktype);
112  void (*free)(void *lock, unsigned locktype);
115  int (*lock)(unsigned mode, void *lock);
118  int (*unlock)(unsigned mode, void *lock);
119 };
120 
129 EVENT2_EXPORT_SYMBOL
131 
132 #define EVTHREAD_CONDITION_API_VERSION 1
133 
134 struct timeval;
135 
148  void *(*alloc_condition)(unsigned condtype);
150  void (*free_condition)(void *cond);
157  int (*signal_condition)(void *cond, int broadcast);
168  int (*wait_condition)(void *cond, void *lock,
169  const struct timeval *timeout);
170 };
171 
180 EVENT2_EXPORT_SYMBOL
182  const struct evthread_condition_callbacks *);
183 
190 EVENT2_EXPORT_SYMBOL
192  unsigned long (*id_fn)(void));
193 
194 #if (defined(_WIN32) && !defined(EVENT__DISABLE_THREAD_SUPPORT)) || defined(EVENT_IN_DOXYGEN_)
195 
199 EVENT2_EXPORT_SYMBOL
204 #define EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 1
205 #endif
206 
207 #if defined(EVENT__HAVE_PTHREADS) || defined(EVENT_IN_DOXYGEN_)
208 
213 EVENT2_EXPORT_SYMBOL
214 int evthread_use_pthreads(void);
215 
216 /* Enables posix mutex priority inheritance
217  * (if pthread_mutexattr_setprotocol() is supported). */
218 #define EVTHREAD_PTHREAD_PRIO_INHERIT 0x01
219 
228 EVENT2_EXPORT_SYMBOL
229 int evthread_use_pthreads_with_flags(int flags);
230 
232 #define EVTHREAD_USE_PTHREADS_IMPLEMENTED 1
233 
234 #endif
235 
242 EVENT2_EXPORT_SYMBOL
244 
245 /* Old (misspelled) version: This is deprecated; use
246  * evthread_enable_log_debugging instead. */
247 EVENT2_EXPORT_SYMBOL
248 void evthread_enable_lock_debuging(void);
249 
250 #endif /* EVENT__DISABLE_THREAD_SUPPORT */
251 
252 struct event_base;
261 EVENT2_EXPORT_SYMBOL
262 int evthread_make_base_notifiable(struct event_base *base);
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif /* EVENT2_THREAD_H_INCLUDED_ */
evthread_set_lock_callbacks
EVENT2_EXPORT_SYMBOL int evthread_set_lock_callbacks(const struct evthread_lock_callbacks *)
Sets a group of functions that Libevent should use for locking.
evthread_enable_lock_debugging
EVENT2_EXPORT_SYMBOL void evthread_enable_lock_debugging(void)
Enable debugging wrappers around the current lock callbacks.
evthread_condition_callbacks
This structure describes the interface a threading library uses for condition variables.
Definition: thread.h:140
evthread_set_id_callback
EVENT2_EXPORT_SYMBOL void evthread_set_id_callback(unsigned long(*id_fn)(void))
Sets the function for determining the thread id.
evthread_lock_callbacks::lock_api_version
int lock_api_version
The current version of the locking API.
Definition: thread.h:98
evthread_lock_callbacks::lock
int(* lock)(unsigned mode, void *lock)
Acquire an already-allocated lock at 'lock' with mode 'mode'.
Definition: thread.h:115
event_base
Structure to hold information and state for a Libevent dispatch loop.
Definition: event.h:219
evthread_condition_callbacks::signal_condition
int(* signal_condition)(void *cond, int broadcast)
Function to signal a condition variable.
Definition: thread.h:157
evthread_lock_callbacks::supported_locktypes
unsigned supported_locktypes
Which kinds of locks does this version of the locking API support? A bitfield of EVTHREAD_LOCKTYPE_RE...
Definition: thread.h:106
evthread_set_condition_callbacks
EVENT2_EXPORT_SYMBOL int evthread_set_condition_callbacks(const struct evthread_condition_callbacks *)
Sets a group of functions that Libevent should use for condition variables.
evthread_condition_callbacks::wait_condition
int(* wait_condition)(void *cond, void *lock, const struct timeval *timeout)
Function to wait for a condition variable.
Definition: thread.h:168
evthread_lock_callbacks::unlock
int(* unlock)(unsigned mode, void *lock)
Release a lock at 'lock' using mode 'mode'.
Definition: thread.h:118
evthread_use_pthreads_with_flags
EVENT2_EXPORT_SYMBOL int evthread_use_pthreads_with_flags(int flags)
Sets up Libevent for use with Pthreads locking and thread ID functions.
evthread_lock_callbacks
This structure describes the interface a threading library uses for locking.
Definition: thread.h:95
evthread_condition_callbacks::free_condition
void(* free_condition)(void *cond)
Function to free a condition variable.
Definition: thread.h:150
evthread_condition_callbacks::condition_api_version
int condition_api_version
The current version of the conditions API.
Definition: thread.h:143
evthread_use_pthreads
EVENT2_EXPORT_SYMBOL int evthread_use_pthreads(void)
Sets up Libevent for use with Pthreads locking and thread ID functions.
evthread_lock_callbacks::free
void(* free)(void *lock, unsigned locktype)
Funtion to release all storage held in 'lock', which was created with type 'locktype'.
Definition: thread.h:112
evthread_make_base_notifiable
EVENT2_EXPORT_SYMBOL int evthread_make_base_notifiable(struct event_base *base)
Make sure it's safe to tell an event base to wake up from another thread or a signal handler.
evthread_use_windows_threads
EVENT2_EXPORT_SYMBOL int evthread_use_windows_threads(void)
Sets up Libevent for use with Windows builtin locking and thread ID functions.