1*7c5f803cSrillig /* $NetBSD: event-internal.h,v 1.5 2021/04/10 19:18:45 rillig Exp $ */ 24109d450Schristos 36448a78cSplunky /* 493dcc084Schristos * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 593dcc084Schristos * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 66448a78cSplunky * 76448a78cSplunky * Redistribution and use in source and binary forms, with or without 86448a78cSplunky * modification, are permitted provided that the following conditions 96448a78cSplunky * are met: 106448a78cSplunky * 1. Redistributions of source code must retain the above copyright 116448a78cSplunky * notice, this list of conditions and the following disclaimer. 126448a78cSplunky * 2. Redistributions in binary form must reproduce the above copyright 136448a78cSplunky * notice, this list of conditions and the following disclaimer in the 146448a78cSplunky * documentation and/or other materials provided with the distribution. 156448a78cSplunky * 3. The name of the author may not be used to endorse or promote products 166448a78cSplunky * derived from this software without specific prior written permission. 176448a78cSplunky * 186448a78cSplunky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 196448a78cSplunky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 206448a78cSplunky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 216448a78cSplunky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 226448a78cSplunky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 236448a78cSplunky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 246448a78cSplunky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 256448a78cSplunky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266448a78cSplunky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 276448a78cSplunky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 286448a78cSplunky */ 29615c371fSchristos #ifndef EVENT_INTERNAL_H_INCLUDED_ 30615c371fSchristos #define EVENT_INTERNAL_H_INCLUDED_ 316448a78cSplunky 326448a78cSplunky #ifdef __cplusplus 336448a78cSplunky extern "C" { 346448a78cSplunky #endif 356448a78cSplunky 3693dcc084Schristos #include "event2/event-config.h" 37615c371fSchristos #include "evconfig-private.h" 38615c371fSchristos 3993dcc084Schristos #include <time.h> 4093dcc084Schristos #include <sys/queue.h> 4193dcc084Schristos #include "event2/event_struct.h" 4293dcc084Schristos #include "minheap-internal.h" 4393dcc084Schristos #include "evsignal-internal.h" 4493dcc084Schristos #include "mm-internal.h" 4593dcc084Schristos #include "defer-internal.h" 466448a78cSplunky 4793dcc084Schristos /* map union members back */ 4893dcc084Schristos 4993dcc084Schristos /* mutually exclusive */ 50615c371fSchristos #define ev_signal_next ev_.ev_signal.ev_signal_next 51615c371fSchristos #define ev_io_next ev_.ev_io.ev_io_next 52615c371fSchristos #define ev_io_timeout ev_.ev_io.ev_timeout 5393dcc084Schristos 5493dcc084Schristos /* used only by signals */ 55615c371fSchristos #define ev_ncalls ev_.ev_signal.ev_ncalls 56615c371fSchristos #define ev_pncalls ev_.ev_signal.ev_pncalls 5793dcc084Schristos 58615c371fSchristos #define ev_pri ev_evcallback.evcb_pri 59615c371fSchristos #define ev_flags ev_evcallback.evcb_flags 60615c371fSchristos #define ev_closure ev_evcallback.evcb_closure 61615c371fSchristos #define ev_callback ev_evcallback.evcb_cb_union.evcb_callback 62615c371fSchristos #define ev_arg ev_evcallback.evcb_arg 63615c371fSchristos 64615c371fSchristos /** @name Event closure codes 65615c371fSchristos 66615c371fSchristos Possible values for evcb_closure in struct event_callback 67615c371fSchristos 68615c371fSchristos @{ 69615c371fSchristos */ 70615c371fSchristos /** A regular event. Uses the evcb_callback callback */ 71615c371fSchristos #define EV_CLOSURE_EVENT 0 72615c371fSchristos /** A signal event. Uses the evcb_callback callback */ 73615c371fSchristos #define EV_CLOSURE_EVENT_SIGNAL 1 74615c371fSchristos /** A persistent non-signal event. Uses the evcb_callback callback */ 75615c371fSchristos #define EV_CLOSURE_EVENT_PERSIST 2 76615c371fSchristos /** A simple callback. Uses the evcb_selfcb callback. */ 77615c371fSchristos #define EV_CLOSURE_CB_SELF 3 78615c371fSchristos /** A finalizing callback. Uses the evcb_cbfinalize callback. */ 79615c371fSchristos #define EV_CLOSURE_CB_FINALIZE 4 80615c371fSchristos /** A finalizing event. Uses the evcb_evfinalize callback. */ 81615c371fSchristos #define EV_CLOSURE_EVENT_FINALIZE 5 82615c371fSchristos /** A finalizing event that should get freed after. Uses the evcb_evfinalize 83615c371fSchristos * callback. */ 84615c371fSchristos #define EV_CLOSURE_EVENT_FINALIZE_FREE 6 85615c371fSchristos /** @} */ 8693dcc084Schristos 8793dcc084Schristos /** Structure to define the backend of a given event_base. */ 886448a78cSplunky struct eventop { 8993dcc084Schristos /** The name of this backend. */ 906448a78cSplunky const char *name; 9193dcc084Schristos /** Function to set up an event_base to use this backend. It should 9293dcc084Schristos * create a new structure holding whatever information is needed to 9393dcc084Schristos * run the backend, and return it. The returned pointer will get 9493dcc084Schristos * stored by event_init into the event_base.evbase field. On failure, 9593dcc084Schristos * this function should return NULL. */ 966448a78cSplunky void *(*init)(struct event_base *); 9793dcc084Schristos /** Enable reading/writing on a given fd or signal. 'events' will be 9893dcc084Schristos * the events that we're trying to enable: one or more of EV_READ, 9993dcc084Schristos * EV_WRITE, EV_SIGNAL, and EV_ET. 'old' will be those events that 10093dcc084Schristos * were enabled on this fd previously. 'fdinfo' will be a structure 10193dcc084Schristos * associated with the fd by the evmap; its size is defined by the 10293dcc084Schristos * fdinfo field below. It will be set to 0 the first time the fd is 10393dcc084Schristos * added. The function should return 0 on success and -1 on error. 10493dcc084Schristos */ 10593dcc084Schristos int (*add)(struct event_base *, evutil_socket_t fd, short old, short events, void *fdinfo); 10693dcc084Schristos /** As "add", except 'events' contains the events we mean to disable. */ 10793dcc084Schristos int (*del)(struct event_base *, evutil_socket_t fd, short old, short events, void *fdinfo); 10893dcc084Schristos /** Function to implement the core of an event loop. It must see which 10993dcc084Schristos added events are ready, and cause event_active to be called for each 11093dcc084Schristos active event (usually via event_io_active or such). It should 11193dcc084Schristos return 0 on success and -1 on error. 11293dcc084Schristos */ 11393dcc084Schristos int (*dispatch)(struct event_base *, struct timeval *); 11493dcc084Schristos /** Function to clean up and free our data from the event_base. */ 11593dcc084Schristos void (*dealloc)(struct event_base *); 11693dcc084Schristos /** Flag: set if we need to reinitialize the event base after we fork. 11793dcc084Schristos */ 1186448a78cSplunky int need_reinit; 11993dcc084Schristos /** Bit-array of supported event_method_features that this backend can 12093dcc084Schristos * provide. */ 12193dcc084Schristos enum event_method_feature features; 12293dcc084Schristos /** Length of the extra information we should record for each fd that 12393dcc084Schristos has one or more active events. This information is recorded 12493dcc084Schristos as part of the evmap entry for each fd, and passed as an argument 12593dcc084Schristos to the add and del functions above. 12693dcc084Schristos */ 12793dcc084Schristos size_t fdinfo_len; 1286448a78cSplunky }; 1296448a78cSplunky 130615c371fSchristos #ifdef _WIN32 13193dcc084Schristos /* If we're on win32, then file descriptors are not nice low densely packed 13293dcc084Schristos integers. Instead, they are pointer-like windows handles, and we want to 13393dcc084Schristos use a hashtable instead of an array to map fds to events. 13493dcc084Schristos */ 13593dcc084Schristos #define EVMAP_USE_HT 13693dcc084Schristos #endif 13793dcc084Schristos 13893dcc084Schristos /* #define HT_CACHE_HASH_VALS */ 13993dcc084Schristos 14093dcc084Schristos #ifdef EVMAP_USE_HT 141615c371fSchristos #define HT_NO_CACHE_HASH_VALUES 14293dcc084Schristos #include "ht-internal.h" 14393dcc084Schristos struct event_map_entry; 14493dcc084Schristos HT_HEAD(event_io_map, event_map_entry); 14593dcc084Schristos #else 14693dcc084Schristos #define event_io_map event_signal_map 14793dcc084Schristos #endif 14893dcc084Schristos 14993dcc084Schristos /* Used to map signal numbers to a list of events. If EVMAP_USE_HT is not 15093dcc084Schristos defined, this structure is also used as event_io_map, which maps fds to a 15193dcc084Schristos list of events. 15293dcc084Schristos */ 15393dcc084Schristos struct event_signal_map { 15493dcc084Schristos /* An array of evmap_io * or of evmap_signal *; empty entries are 15593dcc084Schristos * set to NULL. */ 15693dcc084Schristos void **entries; 15793dcc084Schristos /* The number of entries available in entries */ 15893dcc084Schristos int nentries; 15993dcc084Schristos }; 16093dcc084Schristos 16193dcc084Schristos /* A list of events waiting on a given 'common' timeout value. Ordinarily, 16293dcc084Schristos * events waiting for a timeout wait on a minheap. Sometimes, however, a 16393dcc084Schristos * queue can be faster. 16493dcc084Schristos **/ 16593dcc084Schristos struct common_timeout_list { 16693dcc084Schristos /* List of events currently waiting in the queue. */ 16793dcc084Schristos struct event_list events; 16893dcc084Schristos /* 'magic' timeval used to indicate the duration of events in this 16993dcc084Schristos * queue. */ 17093dcc084Schristos struct timeval duration; 17193dcc084Schristos /* Event that triggers whenever one of the events in the queue is 17293dcc084Schristos * ready to activate */ 17393dcc084Schristos struct event timeout_event; 17493dcc084Schristos /* The event_base that this timeout list is part of */ 17593dcc084Schristos struct event_base *base; 17693dcc084Schristos }; 17793dcc084Schristos 17893dcc084Schristos /** Mask used to get the real tv_usec value from a common timeout. */ 17993dcc084Schristos #define COMMON_TIMEOUT_MICROSECONDS_MASK 0x000fffff 18093dcc084Schristos 18193dcc084Schristos struct event_change; 18293dcc084Schristos 18393dcc084Schristos /* List of 'changes' since the last call to eventop.dispatch. Only maintained 18493dcc084Schristos * if the backend is using changesets. */ 18593dcc084Schristos struct event_changelist { 18693dcc084Schristos struct event_change *changes; 18793dcc084Schristos int n_changes; 18893dcc084Schristos int changes_size; 18993dcc084Schristos }; 19093dcc084Schristos 191615c371fSchristos #ifndef EVENT__DISABLE_DEBUG_MODE 19293dcc084Schristos /* Global internal flag: set to one if debug mode is on. */ 193615c371fSchristos extern int event_debug_mode_on_; 194615c371fSchristos #define EVENT_DEBUG_MODE_IS_ON() (event_debug_mode_on_) 19593dcc084Schristos #else 19693dcc084Schristos #define EVENT_DEBUG_MODE_IS_ON() (0) 19793dcc084Schristos #endif 19893dcc084Schristos 199615c371fSchristos TAILQ_HEAD(evcallback_list, event_callback); 200615c371fSchristos 201615c371fSchristos /* Sets up an event for processing once */ 202615c371fSchristos struct event_once { 203615c371fSchristos LIST_ENTRY(event_once) next_once; 204615c371fSchristos struct event ev; 205615c371fSchristos 206615c371fSchristos void (*cb)(evutil_socket_t, short, void *); 207615c371fSchristos void *arg; 208615c371fSchristos }; 209615c371fSchristos 2106448a78cSplunky struct event_base { 21193dcc084Schristos /** Function pointers and other data to describe this event_base's 21293dcc084Schristos * backend. */ 2136448a78cSplunky const struct eventop *evsel; 21493dcc084Schristos /** Pointer to backend-specific data. */ 2156448a78cSplunky void *evbase; 2166448a78cSplunky 21793dcc084Schristos /** List of changes to tell backend about at next dispatch. Only used 21893dcc084Schristos * by the O(1) backends. */ 21993dcc084Schristos struct event_changelist changelist; 2206448a78cSplunky 22193dcc084Schristos /** Function pointers used to describe the backend that this event_base 22293dcc084Schristos * uses for signals */ 22393dcc084Schristos const struct eventop *evsigsel; 2244109d450Schristos /** Data to implement the common signal handler code. */ 22593dcc084Schristos struct evsig_info sig; 22693dcc084Schristos 22793dcc084Schristos /** Number of virtual events */ 22893dcc084Schristos int virtual_event_count; 229615c371fSchristos /** Maximum number of virtual events active */ 230615c371fSchristos int virtual_event_count_max; 23193dcc084Schristos /** Number of total events added to this event_base */ 23293dcc084Schristos int event_count; 233615c371fSchristos /** Maximum number of total events added to this event_base */ 234615c371fSchristos int event_count_max; 23593dcc084Schristos /** Number of total events active in this event_base */ 23693dcc084Schristos int event_count_active; 237615c371fSchristos /** Maximum number of total events active in this event_base */ 238615c371fSchristos int event_count_active_max; 23993dcc084Schristos 24093dcc084Schristos /** Set if we should terminate the loop once we're done processing 24193dcc084Schristos * events. */ 24293dcc084Schristos int event_gotterm; 24393dcc084Schristos /** Set if we should terminate the loop immediately */ 24493dcc084Schristos int event_break; 24593dcc084Schristos /** Set if we should start a new instance of the loop immediately. */ 24693dcc084Schristos int event_continue; 24793dcc084Schristos 24893dcc084Schristos /** The currently running priority of events */ 24993dcc084Schristos int event_running_priority; 25093dcc084Schristos 25193dcc084Schristos /** Set if we're running the event_base_loop function, to prevent 25293dcc084Schristos * reentrant invocation. */ 25393dcc084Schristos int running_loop; 25493dcc084Schristos 255615c371fSchristos /** Set to the number of deferred_cbs we've made 'active' in the 256615c371fSchristos * loop. This is a hack to prevent starvation; it would be smarter 257615c371fSchristos * to just use event_config_set_max_dispatch_interval's max_callbacks 258615c371fSchristos * feature */ 259615c371fSchristos int n_deferreds_queued; 260615c371fSchristos 26193dcc084Schristos /* Active event management. */ 262615c371fSchristos /** An array of nactivequeues queues for active event_callbacks (ones 263615c371fSchristos * that have triggered, and whose callbacks need to be called). Low 26493dcc084Schristos * priority numbers are more important, and stall higher ones. 26593dcc084Schristos */ 266615c371fSchristos struct evcallback_list *activequeues; 26793dcc084Schristos /** The length of the activequeues array */ 2686448a78cSplunky int nactivequeues; 269615c371fSchristos /** A list of event_callbacks that should become active the next time 270615c371fSchristos * we process events, but not this time. */ 271615c371fSchristos struct evcallback_list active_later_queue; 2726448a78cSplunky 27393dcc084Schristos /* common timeout logic */ 2746448a78cSplunky 27593dcc084Schristos /** An array of common_timeout_list* for all of the common timeout 27693dcc084Schristos * values we know. */ 27793dcc084Schristos struct common_timeout_list **common_timeout_queues; 27893dcc084Schristos /** The number of entries used in common_timeout_queues */ 27993dcc084Schristos int n_common_timeouts; 28093dcc084Schristos /** The total size of common_timeout_queues. */ 28193dcc084Schristos int n_common_timeouts_allocated; 28293dcc084Schristos 28393dcc084Schristos /** Mapping from file descriptors to enabled (added) events */ 28493dcc084Schristos struct event_io_map io; 28593dcc084Schristos 28693dcc084Schristos /** Mapping from signal numbers to enabled (added) events. */ 28793dcc084Schristos struct event_signal_map sigmap; 28893dcc084Schristos 28993dcc084Schristos /** Priority queue of events with timeouts. */ 2906448a78cSplunky struct min_heap timeheap; 2916448a78cSplunky 29293dcc084Schristos /** Stored timeval: used to avoid calling gettimeofday/clock_gettime 29393dcc084Schristos * too often. */ 2946448a78cSplunky struct timeval tv_cache; 29593dcc084Schristos 296615c371fSchristos struct evutil_monotonic_timer monotonic_timer; 297615c371fSchristos 29893dcc084Schristos /** Difference between internal time (maybe from clock_gettime) and 29993dcc084Schristos * gettimeofday. */ 30093dcc084Schristos struct timeval tv_clock_diff; 30193dcc084Schristos /** Second in which we last updated tv_clock_diff, in monotonic time. */ 30293dcc084Schristos time_t last_updated_clock_diff; 30393dcc084Schristos 304615c371fSchristos #ifndef EVENT__DISABLE_THREAD_SUPPORT 30593dcc084Schristos /* threading support */ 30693dcc084Schristos /** The thread currently running the event_loop for this base */ 30793dcc084Schristos unsigned long th_owner_id; 30893dcc084Schristos /** A lock to prevent conflicting accesses to this event_base */ 30993dcc084Schristos void *th_base_lock; 31093dcc084Schristos /** A condition that gets signalled when we're done processing an 31193dcc084Schristos * event with waiters on it. */ 31293dcc084Schristos void *current_event_cond; 31393dcc084Schristos /** Number of threads blocking on current_event_cond. */ 31493dcc084Schristos int current_event_waiters; 31593dcc084Schristos #endif 316615c371fSchristos /** The event whose callback is executing right now */ 317615c371fSchristos struct event_callback *current_event; 31893dcc084Schristos 319615c371fSchristos #ifdef _WIN32 32093dcc084Schristos /** IOCP support structure, if IOCP is enabled. */ 32193dcc084Schristos struct event_iocp_port *iocp; 32293dcc084Schristos #endif 32393dcc084Schristos 32493dcc084Schristos /** Flags that this base was configured with */ 32593dcc084Schristos enum event_base_config_flag flags; 32693dcc084Schristos 327615c371fSchristos struct timeval max_dispatch_time; 328615c371fSchristos int max_dispatch_callbacks; 329615c371fSchristos int limit_callbacks_after_prio; 330615c371fSchristos 33193dcc084Schristos /* Notify main thread to wake up break, etc. */ 33293dcc084Schristos /** True if the base already has a pending notify, and we don't need 33393dcc084Schristos * to add any more. */ 33493dcc084Schristos int is_notify_pending; 33593dcc084Schristos /** A socketpair used by some th_notify functions to wake up the main 33693dcc084Schristos * thread. */ 33793dcc084Schristos evutil_socket_t th_notify_fd[2]; 33893dcc084Schristos /** An event used by some th_notify functions to wake up the main 33993dcc084Schristos * thread. */ 34093dcc084Schristos struct event th_notify; 34193dcc084Schristos /** A function used to wake up the main thread from another thread. */ 34293dcc084Schristos int (*th_notify_fn)(struct event_base *base); 343615c371fSchristos 344615c371fSchristos /** Saved seed for weak random number generator. Some backends use 345615c371fSchristos * this to produce fairness among sockets. Protected by th_base_lock. */ 346615c371fSchristos struct evutil_weakrand_state weakrand_seed; 347615c371fSchristos 348615c371fSchristos /** List of event_onces that have not yet fired. */ 349615c371fSchristos LIST_HEAD(once_event_list, event_once) once_events; 350615c371fSchristos 35193dcc084Schristos }; 35293dcc084Schristos 35393dcc084Schristos struct event_config_entry { 35493dcc084Schristos TAILQ_ENTRY(event_config_entry) next; 35593dcc084Schristos 35693dcc084Schristos const char *avoid_method; 35793dcc084Schristos }; 35893dcc084Schristos 35993dcc084Schristos /** Internal structure: describes the configuration we want for an event_base 36093dcc084Schristos * that we're about to allocate. */ 36193dcc084Schristos struct event_config { 36293dcc084Schristos TAILQ_HEAD(event_configq, event_config_entry) entries; 36393dcc084Schristos 36493dcc084Schristos int n_cpus_hint; 365615c371fSchristos struct timeval max_dispatch_interval; 366615c371fSchristos int max_dispatch_callbacks; 367615c371fSchristos int limit_callbacks_after_prio; 36893dcc084Schristos enum event_method_feature require_features; 36993dcc084Schristos enum event_base_config_flag flags; 3706448a78cSplunky }; 3716448a78cSplunky 3726448a78cSplunky /* Internal use only: Functions that might be missing from <sys/queue.h> */ 3734109d450Schristos #ifndef LIST_END 3744109d450Schristos #define LIST_END(head) NULL 3754109d450Schristos #endif 3764109d450Schristos 37793dcc084Schristos #ifndef TAILQ_FIRST 3786448a78cSplunky #define TAILQ_FIRST(head) ((head)->tqh_first) 37993dcc084Schristos #endif 38093dcc084Schristos #ifndef TAILQ_END 3816448a78cSplunky #define TAILQ_END(head) NULL 38293dcc084Schristos #endif 38393dcc084Schristos #ifndef TAILQ_NEXT 3846448a78cSplunky #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) 38593dcc084Schristos #endif 38693dcc084Schristos 38793dcc084Schristos #ifndef TAILQ_FOREACH 3886448a78cSplunky #define TAILQ_FOREACH(var, head, field) \ 3896448a78cSplunky for ((var) = TAILQ_FIRST(head); \ 3906448a78cSplunky (var) != TAILQ_END(head); \ 3916448a78cSplunky (var) = TAILQ_NEXT(var, field)) 39293dcc084Schristos #endif 39393dcc084Schristos 39493dcc084Schristos #ifndef TAILQ_INSERT_BEFORE 3956448a78cSplunky #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ 3966448a78cSplunky (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ 3976448a78cSplunky (elm)->field.tqe_next = (listelm); \ 3986448a78cSplunky *(listelm)->field.tqe_prev = (elm); \ 3996448a78cSplunky (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ 400*7c5f803cSrillig } while (0) 40193dcc084Schristos #endif 4026448a78cSplunky 40393dcc084Schristos #define N_ACTIVE_CALLBACKS(base) \ 404615c371fSchristos ((base)->event_count_active) 40593dcc084Schristos 406615c371fSchristos int evsig_set_handler_(struct event_base *base, int evsignal, 4076448a78cSplunky void (*fn)(int)); 408615c371fSchristos int evsig_restore_handler_(struct event_base *base, int evsignal); 409615c371fSchristos 410615c371fSchristos int event_add_nolock_(struct event *ev, 411615c371fSchristos const struct timeval *tv, int tv_is_absolute); 412615c371fSchristos /** Argument for event_del_nolock_. Tells event_del not to block on the event 413615c371fSchristos * if it's running in another thread. */ 414615c371fSchristos #define EVENT_DEL_NOBLOCK 0 415615c371fSchristos /** Argument for event_del_nolock_. Tells event_del to block on the event 416615c371fSchristos * if it's running in another thread, regardless of its value for EV_FINALIZE 417615c371fSchristos */ 418615c371fSchristos #define EVENT_DEL_BLOCK 1 419615c371fSchristos /** Argument for event_del_nolock_. Tells event_del to block on the event 420615c371fSchristos * if it is running in another thread and it doesn't have EV_FINALIZE set. 421615c371fSchristos */ 422615c371fSchristos #define EVENT_DEL_AUTOBLOCK 2 4234109d450Schristos /** Argument for event_del_nolock_. Tells event_del to proceed even if the 424615c371fSchristos * event is set up for finalization rather for regular use.*/ 425615c371fSchristos #define EVENT_DEL_EVEN_IF_FINALIZING 3 426615c371fSchristos int event_del_nolock_(struct event *ev, int blocking); 427615c371fSchristos int event_remove_timer_nolock_(struct event *ev); 428615c371fSchristos 429615c371fSchristos void event_active_nolock_(struct event *ev, int res, short count); 4304109d450Schristos EVENT2_EXPORT_SYMBOL 431615c371fSchristos int event_callback_activate_(struct event_base *, struct event_callback *); 432615c371fSchristos int event_callback_activate_nolock_(struct event_base *, struct event_callback *); 433615c371fSchristos int event_callback_cancel_(struct event_base *base, 434615c371fSchristos struct event_callback *evcb); 435615c371fSchristos 436615c371fSchristos void event_callback_finalize_nolock_(struct event_base *base, unsigned flags, struct event_callback *evcb, void (*cb)(struct event_callback *, void *)); 4374109d450Schristos EVENT2_EXPORT_SYMBOL 438615c371fSchristos void event_callback_finalize_(struct event_base *base, unsigned flags, struct event_callback *evcb, void (*cb)(struct event_callback *, void *)); 439615c371fSchristos int event_callback_finalize_many_(struct event_base *base, int n_cbs, struct event_callback **evcb, void (*cb)(struct event_callback *, void *)); 44093dcc084Schristos 44193dcc084Schristos 4424109d450Schristos EVENT2_EXPORT_SYMBOL 443615c371fSchristos void event_active_later_(struct event *ev, int res); 444615c371fSchristos void event_active_later_nolock_(struct event *ev, int res); 445615c371fSchristos int event_callback_activate_later_nolock_(struct event_base *base, 446615c371fSchristos struct event_callback *evcb); 447615c371fSchristos int event_callback_cancel_nolock_(struct event_base *base, 448615c371fSchristos struct event_callback *evcb, int even_if_finalizing); 449615c371fSchristos void event_callback_init_(struct event_base *base, 450615c371fSchristos struct event_callback *cb); 45193dcc084Schristos 45293dcc084Schristos /* FIXME document. */ 4534109d450Schristos EVENT2_EXPORT_SYMBOL 454615c371fSchristos void event_base_add_virtual_(struct event_base *base); 455615c371fSchristos void event_base_del_virtual_(struct event_base *base); 45693dcc084Schristos 45793dcc084Schristos /** For debugging: unless assertions are disabled, verify the referential 45893dcc084Schristos integrity of the internal data structures of 'base'. This operation can 45993dcc084Schristos be expensive. 46093dcc084Schristos 46193dcc084Schristos Returns on success; aborts on failure. 46293dcc084Schristos */ 4634109d450Schristos EVENT2_EXPORT_SYMBOL 464615c371fSchristos void event_base_assert_ok_(struct event_base *base); 465615c371fSchristos void event_base_assert_ok_nolock_(struct event_base *base); 466615c371fSchristos 467615c371fSchristos 468615c371fSchristos /* Helper function: Call 'fn' exactly once every inserted or active event in 469615c371fSchristos * the event_base 'base'. 470615c371fSchristos * 471615c371fSchristos * If fn returns 0, continue on to the next event. Otherwise, return the same 472615c371fSchristos * value that fn returned. 473615c371fSchristos * 474615c371fSchristos * Requires that 'base' be locked. 475615c371fSchristos */ 476615c371fSchristos int event_base_foreach_event_nolock_(struct event_base *base, 477615c371fSchristos event_base_foreach_event_cb cb, void *arg); 478615c371fSchristos 479615c371fSchristos /* Cleanup function to reset debug mode during shutdown. 480615c371fSchristos * 481615c371fSchristos * Calling this function doesn't mean it'll be possible to re-enable 482615c371fSchristos * debug mode if any events were added. 483615c371fSchristos */ 484615c371fSchristos void event_disable_debug_mode(void); 4856448a78cSplunky 4866448a78cSplunky #ifdef __cplusplus 4876448a78cSplunky } 4886448a78cSplunky #endif 4896448a78cSplunky 490615c371fSchristos #endif /* EVENT_INTERNAL_H_INCLUDED_ */ 491