1 .TH "event2/thread.h" 3 "Tue Jan 27 2015" "libevent" \" -*- nroff -*-
7 Functions for multi-threaded applications using Libevent\&.
12 \fC#include <event2/event-config\&.h>\fP
19 .RI "struct \fBevthread_condition_callbacks\fP"
21 .RI "\fIThis structure describes the interface a threading library uses for condition variables\&. \fP"
23 .RI "struct \fBevthread_lock_callbacks\fP"
25 .RI "\fIThis structure describes the interface a threading library uses for locking\&. \fP"
31 .RI "#define \fBEVTHREAD_CONDITION_API_VERSION\fP 1"
34 .RI "#define \fBEVTHREAD_LOCK_API_VERSION\fP 1"
37 .RI "#define \fBEVTHREAD_USE_PTHREADS_IMPLEMENTED\fP 1"
39 .RI "\fIDefined if Libevent was built with support for \fBevthread_use_pthreads()\fP \fP"
41 .RI "#define \fBEVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED\fP 1"
43 .RI "\fIDefined if Libevent was built with support for \fBevthread_use_windows_threads()\fP \fP"
46 .RI "\fBFlags passed to lock functions\fP"
52 .RI "#define \fBEVTHREAD_WRITE\fP 0x04"
54 .RI "\fIA flag passed to a locking callback when the lock was allocated as a read-write lock, and we want to acquire or release the lock for writing\&. \fP"
56 .RI "#define \fBEVTHREAD_READ\fP 0x08"
58 .RI "\fIA flag passed to a locking callback when the lock was allocated as a read-write lock, and we want to acquire or release the lock for reading\&. \fP"
60 .RI "#define \fBEVTHREAD_TRY\fP 0x10"
62 .RI "\fIA flag passed to a locking callback when we don't want to block waiting for the lock; if we can't get the lock immediately, we will instead return nonzero from the locking callback\&. \fP"
66 .RI "\fBTypes of locks\fP"
72 .RI "#define \fBEVTHREAD_LOCKTYPE_RECURSIVE\fP 1"
74 .RI "\fIA recursive lock is one that can be acquired multiple times at once by the same thread\&. \fP"
76 .RI "#define \fBEVTHREAD_LOCKTYPE_READWRITE\fP 2"
84 .RI "void \fBevthread_enable_lock_debuging\fP (void)"
86 .RI "\fIEnable debugging wrappers around the current lock callbacks\&. \fP"
88 .RI "int \fBevthread_make_base_notifiable\fP (struct \fBevent_base\fP *base)"
90 .RI "\fIMake sure it's safe to tell an event base to wake up from another thread or a signal handler\&. \fP"
92 .RI "int \fBevthread_set_condition_callbacks\fP (const struct \fBevthread_condition_callbacks\fP *)"
94 .RI "\fISets a group of functions that Libevent should use for condition variables\&. \fP"
96 .RI "void \fBevthread_set_id_callback\fP (unsigned long(*id_fn)(void))"
98 .RI "\fISets the function for determining the thread id\&. \fP"
100 .RI "int \fBevthread_set_lock_callbacks\fP (const struct \fBevthread_lock_callbacks\fP *)"
102 .RI "\fISets a group of functions that Libevent should use for locking\&. \fP"
104 .RI "int \fBevthread_use_pthreads\fP (void)"
106 .RI "\fISets up Libevent for use with Pthreads locking and thread ID functions\&. \fP"
108 .RI "int \fBevthread_use_windows_threads\fP (void)"
110 .RI "\fISets up Libevent for use with Windows builtin locking and thread ID functions\&. \fP"
112 .SH "Detailed Description"
114 Functions for multi-threaded applications using Libevent\&.
116 When using a multi-threaded application in which multiple threads add and delete events from a single event base, Libevent needs to lock its data structures\&.
118 Like the memory-management function hooks, all of the threading functions \fImust\fP be set up before an \fBevent_base\fP is created if you want the base to use them\&.
120 Most programs will either be using Windows threads or Posix threads\&. You can configure Libevent to use one of these event_use_windows_threads() or event_use_pthreads() respectively\&. If you're using another threading library, you'll need to configure threading functions manually using \fBevthread_set_lock_callbacks()\fP and \fBevthread_set_condition_callbacks()\fP\&.
121 .SH "Macro Definition Documentation"
123 .SS "#define EVTHREAD_LOCKTYPE_RECURSIVE 1"
126 A recursive lock is one that can be acquired multiple times at once by the same thread\&. No other process can allocate the lock until the thread that has been holding it has unlocked it as many times as it locked it\&.
127 .SS "#define EVTHREAD_READ 0x08"
130 A flag passed to a locking callback when the lock was allocated as a read-write lock, and we want to acquire or release the lock for reading\&.
131 .SS "#define EVTHREAD_TRY 0x10"
134 A flag passed to a locking callback when we don't want to block waiting for the lock; if we can't get the lock immediately, we will instead return nonzero from the locking callback\&.
135 .SS "#define EVTHREAD_WRITE 0x04"
138 A flag passed to a locking callback when the lock was allocated as a read-write lock, and we want to acquire or release the lock for writing\&.
139 .SH "Function Documentation"
141 .SS "void evthread_enable_lock_debuging (void)"
144 Enable debugging wrappers around the current lock callbacks\&. If Libevent makes one of several common locking errors, exit with an assertion failure\&.
146 If you're going to call this function, you must do so before any locks are allocated\&.
147 .SS "int evthread_make_base_notifiable (struct \fBevent_base\fP *base)"
150 Make sure it's safe to tell an event base to wake up from another thread or a signal handler\&.
154 0 on success, -1 on failure\&.
158 .SS "int evthread_set_condition_callbacks (const struct \fBevthread_condition_callbacks\fP *)"
161 Sets a group of functions that Libevent should use for condition variables\&. For full information on the required callback API, see the documentation for the individual members of \fBevthread_condition_callbacks\fP\&.
163 Note that if you're using Windows or the Pthreads threading library, you probably shouldn't call this function; instead, use \fBevthread_use_windows_threads()\fP or \fBevthread_use_pthreads()\fP if you can\&.
164 .SS "void evthread_set_id_callback (unsigned long(*)(void)id_fn)"
167 Sets the function for determining the thread id\&.
171 \fIbase\fP the event base for which to set the id function
173 \fIid_fn\fP the identify function Libevent should invoke to determine the identity of a thread\&.
177 .SS "int evthread_set_lock_callbacks (const struct \fBevthread_lock_callbacks\fP *)"
180 Sets a group of functions that Libevent should use for locking\&. For full information on the required callback API, see the documentation for the individual members of \fBevthread_lock_callbacks\fP\&.
182 Note that if you're using Windows or the Pthreads threading library, you probably shouldn't call this function; instead, use \fBevthread_use_windows_threads()\fP or evthread_use_posix_threads() if you can\&.
183 .SS "int evthread_use_pthreads (void)"
186 Sets up Libevent for use with Pthreads locking and thread ID functions\&. Unavailable if Libevent is not build for use with pthreads\&. Requires libraries to link against Libevent_pthreads as well as Libevent\&.
190 0 on success, -1 on failure\&.
194 .SS "int evthread_use_windows_threads (void)"
197 Sets up Libevent for use with Windows builtin locking and thread ID functions\&. Unavailable if Libevent is not built for Windows\&.
201 0 on success, -1 on failure\&.
207 Generated automatically by Doxygen for libevent from the source code\&.