libevent
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
event2/thread.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008-2012 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 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 #include <event2/event-config.h>
00054 
00062 #define EVTHREAD_WRITE  0x04
00063 
00065 #define EVTHREAD_READ   0x08
00066 
00069 #define EVTHREAD_TRY    0x10
00070 
00072 #if !defined(_EVENT_DISABLE_THREAD_SUPPORT) || defined(_EVENT_IN_DOXYGEN)
00073 
00074 #define EVTHREAD_LOCK_API_VERSION 1
00075 
00083 #define EVTHREAD_LOCKTYPE_RECURSIVE 1
00084 /* A read-write lock is one that allows multiple simultaneous readers, but
00085  * where any one writer excludes all other writers and readers. */
00086 #define EVTHREAD_LOCKTYPE_READWRITE 2
00087 
00093 struct evthread_lock_callbacks {
00096         int lock_api_version;
00104         unsigned supported_locktypes;
00107         void *(*alloc)(unsigned locktype);
00110         void (*free)(void *lock, unsigned locktype);
00113         int (*lock)(unsigned mode, void *lock);
00116         int (*unlock)(unsigned mode, void *lock);
00117 };
00118 
00127 int evthread_set_lock_callbacks(const struct evthread_lock_callbacks *);
00128 
00129 #define EVTHREAD_CONDITION_API_VERSION 1
00130 
00131 struct timeval;
00132 
00137 struct evthread_condition_callbacks {
00140         int condition_api_version;
00145         void *(*alloc_condition)(unsigned condtype);
00147         void (*free_condition)(void *cond);
00154         int (*signal_condition)(void *cond, int broadcast);
00165         int (*wait_condition)(void *cond, void *lock,
00166             const struct timeval *timeout);
00167 };
00168 
00177 int evthread_set_condition_callbacks(
00178         const struct evthread_condition_callbacks *);
00179 
00187 void evthread_set_id_callback(
00188     unsigned long (*id_fn)(void));
00189 
00190 #if (defined(WIN32) && !defined(_EVENT_DISABLE_THREAD_SUPPORT)) || defined(_EVENT_IN_DOXYGEN)
00191 
00195 int evthread_use_windows_threads(void);
00199 #define EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 1
00200 #endif
00201 
00202 #if defined(_EVENT_HAVE_PTHREADS) || defined(_EVENT_IN_DOXYGEN)
00203 
00208 int evthread_use_pthreads(void);
00210 #define EVTHREAD_USE_PTHREADS_IMPLEMENTED 1
00211 
00212 #endif
00213 
00220 void evthread_enable_lock_debuging(void);
00221 
00222 #endif /* _EVENT_DISABLE_THREAD_SUPPORT */
00223 
00224 struct event_base;
00230 int evthread_make_base_notifiable(struct event_base *base);
00231 
00232 #ifdef __cplusplus
00233 }
00234 #endif
00235 
00236 #endif /* _EVENT2_THREAD_H_ */