libevent
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_
27 #define _EVENT2_THREAD_H_
28 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 #include <event2/event-config.h>
54 
62 #define EVTHREAD_WRITE 0x04
63 
65 #define EVTHREAD_READ 0x08
66 
69 #define EVTHREAD_TRY 0x10
70 
72 #if !defined(_EVENT_DISABLE_THREAD_SUPPORT) || defined(_EVENT_IN_DOXYGEN)
73 
74 #define EVTHREAD_LOCK_API_VERSION 1
75 
83 #define EVTHREAD_LOCKTYPE_RECURSIVE 1
84 /* A read-write lock is one that allows multiple simultaneous readers, but
85  * where any one writer excludes all other writers and readers. */
86 #define EVTHREAD_LOCKTYPE_READWRITE 2
87 
107  void *(*alloc)(unsigned locktype);
110  void (*free)(void *lock, unsigned locktype);
113  int (*lock)(unsigned mode, void *lock);
116  int (*unlock)(unsigned mode, void *lock);
117 };
118 
128 
129 #define EVTHREAD_CONDITION_API_VERSION 1
130 
131 struct timeval;
132 
145  void *(*alloc_condition)(unsigned condtype);
147  void (*free_condition)(void *cond);
154  int (*signal_condition)(void *cond, int broadcast);
165  int (*wait_condition)(void *cond, void *lock,
166  const struct timeval *timeout);
167 };
168 
178  const struct evthread_condition_callbacks *);
179 
188  unsigned long (*id_fn)(void));
189 
190 #if (defined(WIN32) && !defined(_EVENT_DISABLE_THREAD_SUPPORT)) || defined(_EVENT_IN_DOXYGEN)
191 
199 #define EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 1
200 #endif
201 
202 #if defined(_EVENT_HAVE_PTHREADS) || defined(_EVENT_IN_DOXYGEN)
203 
208 int evthread_use_pthreads(void);
210 #define EVTHREAD_USE_PTHREADS_IMPLEMENTED 1
211 
212 #endif
213 
221 
222 #endif /* _EVENT_DISABLE_THREAD_SUPPORT */
223 
224 struct event_base;
230 int evthread_make_base_notifiable(struct event_base *base);
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 
236 #endif /* _EVENT2_THREAD_H_ */
int evthread_set_lock_callbacks(const struct evthread_lock_callbacks *)
Sets a group of functions that Libevent should use for locking.
This structure describes the interface a threading library uses for condition variables.
Definition: thread.h:137
int evthread_set_condition_callbacks(const struct evthread_condition_callbacks *)
Sets a group of functions that Libevent should use for condition variables.
int evthread_use_windows_threads(void)
Sets up Libevent for use with Windows builtin locking and thread ID functions.
int(* lock)(unsigned mode, void *lock)
Acquire an already-allocated lock at &#39;lock&#39; with mode &#39;mode&#39;.
Definition: thread.h:113
void evthread_set_id_callback(unsigned long(*id_fn)(void))
Sets the function for determining the thread id.
int lock_api_version
The current version of the locking API.
Definition: thread.h:96
int condition_api_version
The current version of the conditions API.
Definition: thread.h:140
int evthread_make_base_notifiable(struct event_base *base)
Make sure it&#39;s safe to tell an event base to wake up from another thread or a signal handler...
void(* free)(void *lock, unsigned locktype)
Funtion to release all storage held in &#39;lock&#39;, which was created with type &#39;locktype&#39;.
Definition: thread.h:110
int(* unlock)(unsigned mode, void *lock)
Release a lock at &#39;lock&#39; using mode &#39;mode&#39;.
Definition: thread.h:116
This structure describes the interface a threading library uses for locking.
Definition: thread.h:93
int evthread_use_pthreads(void)
Sets up Libevent for use with Pthreads locking and thread ID functions.
void evthread_enable_lock_debuging(void)
Enable debugging wrappers around the current lock callbacks.
unsigned supported_locktypes
Which kinds of locks does this version of the locking API support? A bitfield of EVTHREAD_LOCKTYPE_RE...
Definition: thread.h:104
Structure to hold information and state for a Libevent dispatch loop.
Definition: event.h:213