libevent

include/event2/thread.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008-2010 Niels Provos and Nick Mathewson
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 1. Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  * 2. Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  * 3. The name of the author may not be used to endorse or promote products
00013  *    derived from this software without specific prior written permission.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00016  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00017  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00018  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00019  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00020  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00021  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00022  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00024  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025  */
00026 #ifndef _EVENT2_THREAD_H_
00027 #define _EVENT2_THREAD_H_
00028 
00056 #ifdef __cplusplus
00057 extern "C" {
00058 #endif
00059 
00060 #include <event2/event-config.h>
00061 
00064 #define EVTHREAD_WRITE  0x04
00065 
00067 #define EVTHREAD_READ   0x08
00068 
00071 #define EVTHREAD_TRY    0x10
00072 
00073 #ifndef _EVENT_DISABLE_THREAD_SUPPORT
00074 
00075 #define EVTHREAD_LOCK_API_VERSION 1
00076 
00080 #define EVTHREAD_LOCKTYPE_RECURSIVE 1
00081 /* A read-write lock is one that allows multiple simultaneous readers, but
00082  * where any one writer excludes all other writers and readers. */
00083 #define EVTHREAD_LOCKTYPE_READWRITE 2
00084 
00089 struct evthread_lock_callbacks {
00092         int lock_api_version;
00100         unsigned supported_locktypes;
00103         void *(*alloc)(unsigned locktype);
00106         void (*free)(void *lock, unsigned locktype);
00109         int (*lock)(unsigned mode, void *lock);
00112         int (*unlock)(unsigned mode, void *lock);
00113 };
00114 
00123 int evthread_set_lock_callbacks(const struct evthread_lock_callbacks *);
00124 
00125 #define EVTHREAD_CONDITION_API_VERSION 1
00126 
00127 struct timeval;
00128 
00133 struct evthread_condition_callbacks {
00136         int condition_api_version;
00141         void *(*alloc_condition)(unsigned condtype);
00143         void (*free_condition)(void *cond);
00150         int (*signal_condition)(void *cond, int broadcast);
00161         int (*wait_condition)(void *cond, void *lock,
00162             const struct timeval *timeout);
00163 };
00164 
00173 int evthread_set_condition_callbacks(
00174         const struct evthread_condition_callbacks *);
00175 
00183 void evthread_set_id_callback(
00184     unsigned long (*id_fn)(void));
00185 
00186 #if defined(WIN32) && !defined(_EVENT_DISABLE_THREAD_SUPPORT)
00187 
00191 int evthread_use_windows_threads(void);
00192 #define EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 1
00193 #endif
00194 
00195 #if defined(_EVENT_HAVE_PTHREADS)
00196 
00201 int evthread_use_pthreads(void);
00202 #define EVTHREAD_USE_PTHREADS_IMPLEMENTED 1
00203 
00204 #endif
00205 
00209 void evthread_enable_lock_debuging(void);
00210 
00211 #endif /* _EVENT_DISABLE_THREAD_SUPPORT */
00212 
00213 struct event_base;
00219 int evthread_make_base_notifiable(struct event_base *base);
00220 
00221 #ifdef __cplusplus
00222 }
00223 #endif
00224 
00225 #endif /* _EVENT2_THREAD_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines