document thread functions

svn:r688
This commit is contained in:
Niels Provos 2008-03-04 05:42:20 +00:00
parent d5c15b2ebb
commit 0c49e456f1
2 changed files with 42 additions and 2 deletions

View File

@ -55,7 +55,7 @@ SORT_BRIEF_DOCS = YES
# with spaces. # with spaces.
INPUT = event.h evdns.h evhttp.h evrpc.h \ INPUT = event.h evdns.h evhttp.h evrpc.h \
include/event2/buffer.h include/event2/buffer.h include/event2/thread.h
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# configuration options related to the HTML output # configuration options related to the HTML output

View File

@ -28,6 +28,26 @@
#define _EVENT2_THREAD_H_ #define _EVENT2_THREAD_H_
/** @file thread.h /** @file thread.h
Functions for multi-threaded applications using libevent.
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.
A multi-threaded application must provide locking functions to
libevent via evthread_set_locking_callback(). Libevent will invoke
this callback whenever a lock needs to be acquired or released.
The total number of locks employed by libevent can be determined
via the evthread_num_locks() function. An application must provision
that many locks.
If the owner of an event base is waiting for events to happen,
libevent may signal the thread via a special file descriptor to wake
up. To enable this feature, an application needs to provide a
thread identity function via evthread_set_id_callback().
*/ */
#ifdef __cplusplus #ifdef __cplusplus
@ -42,12 +62,32 @@ extern "C" {
#define EVTHREAD_WRITE 0x04 #define EVTHREAD_WRITE 0x04
#define EVTHREAD_READ 0x08 #define EVTHREAD_READ 0x08
/** returns the number of locks that need to be allocated */ /**
returns the number of locks that need to be allocated
@return the number of locks required by libevent
*/
int evthread_num_locks(); int evthread_num_locks();
struct event_base; struct event_base;
/**
Sets the function libevent should use for locking.
@param base the event base for which the locking function should be set
@param locking_fn the function that libevent should invoke to acquire
or release a lock. mode has either EVTHREAD_LOCK or EVTHREAD_UNLOCK
set, and in addition, either EVHTREAD_WRITE or EVTREAD_READ.
*/
void evthread_set_locking_callback(struct event_base *base, void evthread_set_locking_callback(struct event_base *base,
void (*locking_fn)(int mode, int locknum)); void (*locking_fn)(int mode, int locknum));
/**
Sets the function for derminting the thread id.
@param base the event base for which to set the id function
@param id_fn the identify function libevent should invoke to
determine the identity of a thread.
*/
void evthread_set_id_callback(struct event_base *base, void evthread_set_id_callback(struct event_base *base,
unsigned long (*id_fn)(void)); unsigned long (*id_fn)(void));