event.c


Log

Author Commit Date CI Message
Nick Mathewson a3cec909 2012-02-20T14:07:08 Remove the last vestiges of _EVENT_USE_EVENTLIST
Nick Mathewson 8dbcf8d6 2012-02-20T13:56:13 Merge branch '21_eventlist_v3_squashed'
Nick Mathewson c89b4e63 2012-02-11T21:01:53 Refactor the functions that run over every event. Now there are appropriate "for each event", "for each fd", and "for each signal" helpers that they can use; this makes the code a bit simpler, and far less duplicated. This lets me turn back on the functions I disabled when removing eventlist. Additionally, check more lists for circularity in event_base_assert_ok(). Add typedefs for the callback types. Name fewer things "ctx". Adds an implementation of Floyd's tortoise-and-hare algorithm to check for circularity in TAILQs and LISTs, to avoid the abuse of flags that event_base_assert_ok() was doing before. Suggested by Dave Hart.
Nick Mathewson a220a081 2012-02-15T21:07:44 Merge remote-tracking branch 'github/21_fast_syscalls'
Nick Mathewson 46e5bb7b 2012-02-13T17:59:14 Invert the sense and the name of HT_CACHE_HASH_VALUES This is meant to make it easier to merge ht-internal.h back upstream into Tor.
Nick Mathewson 2b0a2c45 2012-02-10T18:04:04 Fix compilation on osx
Nick Mathewson 539466e5 2012-02-10T17:33:50 Merge remote-tracking branch 'origin/patches-2.0' Conflicts: Makefile.am WIN32-Code/event2/event-config.h configure.in
Nick Mathewson e49e2891 2012-02-10T17:29:53 Update copyright notices to 2012
Nick Mathewson ca76cd93 2012-02-10T16:15:10 Use a wrapper function to create the notification pipe/socketpair/eventfd
Sebastian Hahn e4a56ed5 2012-01-31T18:58:59 Fix a compile warning in event_reinit Introduced in 272033efe575a9dc7ec6f123a96afba5c69ff1c6
Nick Mathewson 604569bf 2012-01-27T16:35:04 Remove the eventqueue list and the ev_next pointers. Those pointers were once used to maintain a complete list of inserted IO and signal events. But such a list is now available by walking over ev_io_map and ev_signal_map! So all they did was require extra pointer operations to maintain, and extra 8-16 bytes of storage in each struct event. To be cowardly and keep the option of going back to having this redundancy, I'm wrapping the removed code in a set of ifdefs. This is a first cut; it needs cleanups and stress-testing!! In particular, it just plain disables a couple of functions that could probably be saved. There seems to be a need for an evmap_{io,signal}_foreach() or something.
Nick Mathewson 2c4b5de1 2012-01-27T14:30:41 Restore fast-path event_reinit() for slower backends We used to use the needs_reinit flag in struct eventop to indicate whether an event backend had shared state across a fork(), and therefore would require us to construct a new event backend. But when we realized that the signal notification fds and the thread notification fds would always be shared across forks, we stopped looking at it. This patch restores the old behavior so that poll, select, and win32select don't need to do a linear scan over all pending fds/signals when they do a reinit. Their life is hard enough already.
Nick Mathewson 272033ef 2012-01-27T13:54:05 Make event_reinit() more robust and maintainable Previously, event_reinit required a bunch of really dubious hacks, and violated a lot of abstraction barriers to mess around with lists of internal events and "pretend" to re-add them. The new (and fairly well commented!) implementation tries to be much smarter, by isolating the changes as much as possible to the backend state, and minimizing the amount of abstraction violations. Specifically, we now use event_del() to remove events we want to remove, rather than futzing around with queues in event_reinit(). To avoid bogus calls to evsel->del(), we temporarily replace evsel with a null-object stub. Also, we now push the responsibility for calling evsel->add() down into the evmap code, so that we don't actually need to unlink and re-link all of our events.
Nick Mathewson fe0afabb 2012-01-24T10:29:31 Merge remote-tracking branch 'origin/patches-2.0' Conflicts: event.c Edits required in: evmap.c
Nick Mathewson 3f18ad1b 2012-01-23T18:15:44 Fix a fd leak in event_reinit() We were supposed to be closing the ev_signal_pair sockets.
Nick Mathewson 6e41cdc1 2012-01-23T17:59:16 Fix a list corruption bug when using event_reinit() with signals present While re-adding all the events, event_reinit() could add a signal event, which could then cause evsig_add() to add the base->sig.ev_signal event. Later on its merry path through base->eventqueue, event_reinit() would find that same event and give it to event_io_add a second time. This would make the ev_io_next list for that fd become circular. Ouch!
Nick Mathewson 27737d55 2012-01-21T12:55:15 Add function to check referential integrity of an event_base
Nick Mathewson d5a3fe5f 2012-01-09T12:00:04 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson f0325167 2012-01-09T11:33:38 Remove bogus casts of socket to int before calling ev_callback This should make 64-bit windows act better. Found by Mark Heily.
Nick Mathewson 35c5c955 2011-12-07T11:49:52 Bypass event_add when using event_base_once() for a 0-sec timeout Some people use event_base_once(EV_TIMEOUT) to make a callback get called "immediately". But this is pretty roundabout: it uses the timeout heap to immediately put the event onto the active queue, when it could just use event_active. Additionally, it can lead to surprising re-ordering behavior. This patch changes event_base_once so it bypasses event_add() and called event_active() directly on a pure-timeout event with an empty timeout.
Nick Mathewson 9ce5053d 2011-12-06T11:02:12 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson 11f36a5f 2011-12-05T15:02:27 Be absolutely sure to clear pncalls before leaving event_signal_closure I thought we'd fixed the cases where this could come up, but apparently having an event_base_break() happen while processing signal events could get us in trouble. Found by Remi Gacogne. Sourceforge issue 3451433 .
Nick Mathewson f5b937e6 2011-11-14T18:22:08 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson e7874133 2011-11-14T17:33:02 Don't try to make notifiable event_base when no threading fns are configured
Nick Mathewson 4e797f38 2011-11-14T17:32:22 Warn when unable to construct base because of failing make_base_notifiable
Nick Mathewson 0cb70e33 2011-10-26T10:17:21 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson 3c824bd3 2011-10-24T13:18:09 Update copyright dates to 2011.
Abel Mathew 212533e4 2011-10-21T19:53:32 New event_base_update_cache_time() to set cached_tv to current time This function is particularly useful for selectively increasing the accuracy of the cached time value in 'base' during callbacks that take a long time to execute. This function has no effect if the base is currently not in its event loop or if timeval caching is disabled via EVENT_BASE_FLAG_NO_CACHE_TIME.
Mansour Moufid c8953d1b 2011-10-14T17:16:03 Add argument checks to some memory functions in `event.c'. Add a zero check to the function `event_mm_malloc_', i.e. simply return NULL if the sz argument is zero. On failure, set errno to ENOMEM and return NULL. Add a zero check to the function `event_mm_calloc_', i.e. simply return NULL if either argument is zero. Also add an unsigned integer multiplication check, and if an integer overflow would occur, set errno to ENOMEM and return NULL. On failure, set errno to ENOMEM and return NULL. Add a NULL check to the function `event_mm_strdup_', i.e. set errno to EINVAL and return NULL. Also add an unsigned integer addition check, and if an integer overflow would occur, set errno to ENOMEM and return NULL. If a memory allocation error occurs, again set errno to ENOMEM and return NULL. Add unit tests to `test/regress_util.c'.
Nick Mathewson 128c8d6c 2011-10-19T22:44:33 Merge remote-tracking branch 'origin/patches-2.0'
Leonid Evdokimov 9e6a4efa 2011-10-19T17:44:17 More detailed message in case of libevent self-debugging failure.
Nick Mathewson 3c55b5ee 2011-10-11T09:50:57 Make evbase_priority_init() and evbase_get_npriorities() threadsafe
Alexander Drozdov ee3a4ee8 2011-10-11T11:12:34 Add event_base_get_npriorities() function.
Nick Mathewson 084e68f3 2010-12-01T21:53:08 New EVLOOP_NO_EXIT_ON_EMPTY option to keep looping even when no events are pending This can be useful if you want to start an event loop and then add or remove events to it from another thread.
Nick Mathewson 1ebe7955 2011-09-26T11:11:30 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson 4e8eb6a5 2011-09-09T20:53:30 When a signal callback is activated to run multiple times, allow event_base_loopbreak to work even before they all have run. Found by Abilio Marques.
Nick Mathewson 2cbe115c 2011-08-24T16:17:56 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson 5b18f130 2011-08-24T16:17:05 Make rate limiting work with common_timeout logic
Nick Mathewson 3c63edd1 2011-08-11T12:47:21 Make the priority inversion code use gettime(), not evutil_gettimeofday() Since we're computing the time after each callback, we might as well update the time cache (if we're using it) and use monotonic time (if we've got that).
Nick Mathewson a37a0c0e 2011-08-11T12:38:47 Make max_dispatch_interval able to apply only to low-priority events Suggested by Alexander Drozdov
Alexander Drozdov a9866aa8 2011-07-22T12:29:07 Optimization in event_process_active(): ignore maxcb & endtime for highest priority events.
Nick Mathewson 9fa56bdf 2011-08-11T11:59:23 Make sure max_dispatch_callbacks is never negative Suggested by Alexander Drozdov.
Nick Mathewson fd4de1e7 2010-12-01T20:44:05 Add event_config function to limit time/callbacks between calls to dispatch
Mark Ellzey 67275433 2011-08-11T16:53:01 more event dbg updates
Mark Ellzey 4b7d2984 2011-08-11T13:25:24 added timeout debug logs to include event ptr.
Mark Ellzey 3baab0dc 2011-08-11T12:06:54 Added usec debug in another area for debug
Mark Ellzey ac43ce04 2011-08-11T11:56:26 Debug addition for printing usec on TIMEOUT debugging.
Nick Mathewson e91d57f1 2011-08-08T16:20:53 Merge remote-tracking branch 'github/21_split_functions' Conflicts: event.c The conflicts were with the 21_faster_timeout_adj branch, which added a "reinsert" function that needed to get renamed to "reinsert_timeout". Also, some of the code that 21_split_functions changes got removed by 21_faster_timeout_adj.
Nick Mathewson 24e24805 2011-08-08T16:17:18 Merge remote-tracking branch 'github/21_faster_timeout_adj'
Nick Mathewson 78fb99ce 2011-07-04T12:22:54 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson e7fe9270 2011-07-04T12:16:08 Merge remote-tracking branch 'github/20_global_locks_init' into patches-2.0
Nick Mathewson 5099d858 2011-06-08T14:29:36 Merge remote-tracking branch 'origin/patches-2.0'
Nick Mathewson 09fe97da 2011-06-08T14:24:45 Replace an assertion for event_base_free(NULL) with a check-and-warn event_base_free(NULL) means "free the current event base". Previously, it would assert if there was no 'current' base. Now it just warns and returns. Reported by Gilad Benjamini
Nick Mathewson e40bafe7 2011-06-04T21:40:55 Merge remote-tracking branch 'origin/patches-2.0' Conflicts: Makefile.am WIN32-Code/event2/event-config.h configure.in test/regress_ssl.c
Nick Mathewson 27ce38b6 2011-06-01T17:27:28 Avoid a segfault when all methods are disabled or broken
Nick Mathewson 94b8e676 2011-05-27T22:54:16 Allow base-notification functions to exist without setting an fd The kqueue and evport backends can make good use of this.
Nick Mathewson 9f560bfa 2011-05-25T19:50:56 Use "_WIN32", not WIN32: it's standard and we don't need to fake it This patch was automatically generated with perl. Based on a patch by Peter Rosin.
Nick Mathewson b683cae3 2011-04-22T12:01:25 Avoid race-condition when initializing global locks Previously, we did stuff like if (!lock) EVTHREAD_ALLOC_LOCK(lock,0); for the evsig base global lock, the arc4random lock, and the debug_map lock. But that's potentially racy! Instead, we move the responisiblity for global lock initialization to the functions where we set up the lock callbacks. (Rationale: We already require that you set up the locking callbacks before you create any event_base, and that you do so exatly once.)
Nick Mathewson 2a83ecc8 2011-03-07T23:01:54 In the 2.1 branch, let's try out lazy gettimeofday/clock_gettime comparison For now, we'll only check for gettimeofday jumps once every 5 seconds. Let's see how that works. This reverts commit 5209fadfd07af3f3379ac607582c37933b33e044.
Nick Mathewson 4560b31b 2011-03-07T23:00:45 Merge remote branch 'origin/patches-2.0' Conflicts: event-internal.h
Nick Mathewson 5209fadf 2011-03-07T22:59:19 Disable lazy gettimeofday/clock_gettime comparison for now
Nick Mathewson a459ef70 2011-03-03T15:34:22 Have event_base_gettimeofday_cached() always return wall-clock time Based on code by Dave Hart
Nick Mathewson d1cee3b1 2011-02-23T01:08:54 Make event_count maintainance branchless at the expense of an extra shift. Needs benchmarking
Nick Mathewson efc4dc50 2011-02-23T00:59:20 possible optimization: split event_queue_insert/remove into separate functions. needs testing
Nick Mathewson 77a96fd9 2011-02-02T20:09:16 Remove a needless base-notify when rescheduling the first timeout We don't need to wake up the base when rescheduling the timeout that will expire first: the base will already wake up, see that nothing is ready, and go back to sleep.
Nick Mathewson e47042fe 2011-02-02T20:05:41 Optimize the case where we reinsert an existing timeout
Kevin Bowling 0915ca0a 2011-01-02T08:43:45 Include evconfig-private.h in internal files for great good.
Nick Mathewson 5beeec9d 2010-12-01T21:28:03 Correctly notify the main thread when activating an event from a subthread
Nick Mathewson 2e5a175b 2010-11-25T23:03:46 Merge remote branch 'github/20_once_fixes'
Nick Mathewson 652024b6 2010-11-23T13:08:07 Remove _event_initialized(); make event_initialized() a function(); make it consistent on windows and non-windows
Nick Mathewson 3ab578f8 2010-11-20T01:41:34 Make sure the CLOEXEC flag is set on fds we open for base notification
Nick Mathewson 2d5e1bd0 2010-11-14T19:32:13 Do not let EVLOOP_ONCE exit the loop until all deferred callbacks have run
Nick Mathewson 0617a818 2010-11-14T19:25:54 Make EVLOOP_ONCE ignore internal events Merely getting an internal notification event from having an event added or deleted from another thread should not cause event_base_loop(base, EVLOOP_ONCE) to exit; previously, it did.
Nick Mathewson b81217f7 2010-10-27T17:37:32 Fix signal handler types for win64.
Nick Mathewson 19c71e74 2010-10-27T10:36:08 Fix som event_warns that should have been event_warnx
Nick Mathewson e56ff65a 2010-10-26T11:01:58 Fix a minor syntax error that most compilers didn't care about
Nick Mathewson 7ad90f6a 2010-10-09T00:02:31 Merge branch '20_internal_prio'
Nick Mathewson e1198997 2010-09-21T22:44:39 Make event.c debugging messages report fds
Nick Mathewson 90651b32 2010-09-17T00:24:50 Put internal events at highest priority (If we allow user events to starve internal events, then internal events never actually happen, signals don't get acked, etc)
Nick Mathewson 720bd933 2010-09-15T01:08:39 Warn when using the error-prone EV_SIGNAL interface in an error-prone way. Also, fix a couple of race conditions in signal.c When using the signal.c signal backend, Libevent currently only allows one event_base to actually receive signals at a time. (This has been the behavior since at least 1.4 and probably much earlier.) Now, we detect and warn if you're likely to be racing about which signal goes to which thread. We also add a lock to control modifications of the evsig_base field, to avoid race conditions like those found by Jason Toffaletti. Also, more comments. Comments are good.
Christopher Davis d98511c0 2010-09-09T14:36:45 Make event_base_virtual_del() notify the base if needed
Christopher Davis 71b68014 2010-09-08T20:33:21 Don't decrement virutal event count twice in connect_complete.
Nick Mathewson 3658b169 2010-09-08T14:12:12 Merge remote branch 'chrisd/iocp-fixes4' Conflicts: test/regress_thread.c
Nick Mathewson 4632b78e 2010-09-08T13:22:55 Minimize calls to base_notify implementation functions, thereby avoiding needless syscalls The trick here is that if we already told the base to wake up, and it hasn't woken up yet, we don't need to tell it to wake up again. This should help lots with inherently multithreaded code like IOCP.
Nick Mathewson c7a06bfa 2010-09-08T13:02:58 Avoid needlessly calling evthread_notify_base() when the loop is not running Also make sure that we always hold the base lock when calling evthread_notify_base.
Christopher Davis 17a14f1a 2010-09-01T11:04:57 Only process up to MAX_DEFERRED deferred_cbs at a time. If threads queue callbacks while event_process_deferred_callbacks is running, the loop may spin long enough to significantly skew timers. A unit test stressing this behavior is also in this commit.
Christopher Davis 2447fe88 2010-08-28T04:07:48 Add event_config_set_num_cpus_hint for tuning thread pools, etc.
Christopher Davis 76f7e7ae 2010-08-17T05:02:00 Some IOCP bufferevent tweaks. - Increment reference count of bufferevents before initiating overlapped operations to prevent the destructor from being called while operations are pending. The only portable way of canceling overlapped ops is to close the socket. - Translate error codes to WSA* codes. - Better handling of errors. - Add an interface to add and del "virtual" events. Because IOCP bufferevents don't register any events with the base, the event loop has no way of knowing they exist. This causes the loop to terminate prematurely. event_base_{add,del}_virtual increment/decrement base's event count so the loop runs while there are any enabled IOCP bufferevents.
Christopher Davis d844242f 2010-08-28T02:08:27 Stop IOCP when freeing the event_base.
Nick Mathewson 495ed667 2010-09-01T16:36:30 Close th_notify_fds and open a new pair on reinit After a fork, you want subthreads to wake up the event_base in the child process, not to have the child process and the main process fight over who wakes up whom. Related to a problem found by Nicholas Marriott while debugging 3048812.
Nick Mathewson d61b2f33 2010-08-26T15:09:58 Fix an issue with forking and signal socketpairs in select/poll backends Nicholas Marriott identifies an issue where a signal socketpair doesn't get recreated if the event backend doesn't set event_reinit. See bug 3048812 There may be a similar issue with respect to th_notify_fd
Nick Mathewson f1074b77 2010-08-23T12:01:45 Detect events with no ev_base; warn instead of crashing
Nick Mathewson e0972c21 2010-08-17T13:18:18 Use conditions instead of current_event_lock to fix a deadlock. Avi Bab correctly noted as bug 3044479 the fact that any thread blocking on current_event_lock will do so while holding th_base_lock, making it impossible for the currently running event's callback to call any other functions that require th_base_lock. This patch switches the current_event_lock code to instead use a condition variable that we wait on if we're trying to mess with a currently-executing event, and that we signal when we're done executing a callback if anybody is waiting on it.
Nick Mathewson ec347b92 2010-07-07T16:45:03 Move event-config.h to include/event2 This change means that all required include files are in event2, and all files not in event2/* are optional.
Nick Mathewson 42a8c711 2010-07-31T17:10:04 Build more cleanly with NetBSDs that dislike toupper(char) To be fair, when char can be signed, if toupper doesn't take negative characters, toupper(char) is a very bad idea. So let's just use the nice safe EVUTIL_TOUPPER instead. (It explicitly only upcases ASCII, but we only use it for identifiers that we know to be ASCII anyway).
Nick Mathewson fc5e0a23 2010-07-05T14:39:39 Don't race when calling event_active/event_add on a running signal event There was previously no lock protecting the signal event's ev_ncalls/ev_pncalls fields, which were accessed by all of event_signal_closure, event_add_internal, event_del_internal, and event_active_nolock. This patch fixes this race by using the current_event_lock in the same way it's used to prevent event_del_internal from touching an event that's currently running.
Nick Mathewson 61e1eeec 2010-07-05T13:24:45 Tidy up the code in evthread_make_base_notifiable a little Previously, we had a few conditional statements with the "if (...)" inside an #ifdef and the body outside. That kind of thing is hard to read.
Nick Mathewson a5bc15b2 2010-07-05T13:24:12 Drain th_notify_fd[0] more bytes at a time.
Nick Mathewson 17522d2a 2010-07-05T13:17:47 Fix a deadlock related to event-base notification. Diagnosed by Zhou Li, Avi Bab, and Scott Lamb. The problem was that the thread doing the notification could block on write in evthread_notify_base_default while holding the th_base_lock. The main thread would never drain th_notify_fd[0], since it would need th_base_lock to actually trigger events.
Nick Mathewson 6d195109 2010-05-13T14:59:33 Avoid event_del on uninitialized event in event_base_free This was mostly harmless, since the event was cleared with calloc, but still it's not a correct thing to do.