45 Commits

Author SHA1 Message Date
Nick Mathewson
a66e947b8b Use less memory for each entry in a hashtable
Our hash-table implementation stored a copy of the hash code in each
element.  But as we were using it, all of our hash codes were
ridiculously easy to calculate: most of them were just a matter of a
load and a shift.

This patch lets ht-internal be built in either of two ways: one caches
the hash-code for each element, and one recalculates it each time it's
needed.

This patch also chooses a slightly better hash code for
event_debug_entry.
2010-01-25 13:53:17 -05:00
Nick Mathewson
cd17c3acd5 Add support for a "debug mode" to try to catch common errors.
Right now it only catches cases where we aren't initializing events,
or where we are re-initializing events without deleting them first.
These are however shockingly common.
2010-01-25 13:53:13 -05:00
Nick Mathewson
27308aae4d Changelist code to defer event changes until just before dispatch
This is necessary or useful for a few reasons:

    1) Sometimes applications will add and delete the same event more
       than once between calls to dispatch.  Processing these changes
       immediately is needless, and potentially expensive (especially
       if we're on a system that makes one syscall per changed event).

       Yes, this actually happens in practice for nonpathological
       code, such as in cases where the user's callback conditionally
       re-adds a non-persistent event, or where draining a buffer
       turns off writing and invokes a user callback which adds more
       data which in turn re-enabled writing.

    2) Sometimes we can coalesce multiple changes on the same fd into
       a single syscall if we know about them in advance.  For
       example, epoll can do an add and a delete at the same time, but
       only if we have found out about both of them before we tell
       epoll.

    3) Sometimes adding an event that we immediately delete can cause
       unintended consequences: in kqueue, this makes pending events
       get reported spuriously.
2010-01-14 16:31:22 -05:00
Nick Mathewson
74871cacb8 Change event_base.activequeues to "array of eventlist".
Previously, event_base.activequeues was of type "array of pointers to
eventlist."  This was pointless: none of the eventlists were allowed
to be NULL.  Worse, it was inefficient:

  - It made looking up an active event queue take two pointer
    deferences instead of one, thus risking extra cache misses.
  - It used more RAM than it needed to, because of the extra pointer
    and the malloc overhead.

Also, this patch fixes a bug where we were saying
calloc(N,N*sizeof(X)) instead of calloc(N,sizeof(X)) when allocating
activequeues.  That part, I'll backport.

Also, we warn and return -1 on failure to allocate activequeues,
rather than calling event_err.

svn:r1525
2009-11-09 19:37:27 +00:00
Nick Mathewson
ab96b5f3f5 Add an option to disable the timeval cache.
svn:r1518
2009-11-09 18:30:33 +00:00
Nick Mathewson
693c24ef9d Implement queued timeouts for case where many timeouts are the same.
Libevent's current timeout code is relatively optimized for the
randomly scattered timeout case, where events are added with their
timeouts in no particular order.  We add and remove timeouts with
O(lg n) behavior.

Frequently, however, an application will want to have many timeouts
of the same value.  For example, we might have 1000 bufferevents,
each with a 2 second timeout on reading or writing.  If we knew this
were always the case, we could just put timeouts in a queue and get
O(1) add and remove behavior.  Of course, a queue would give O(n)
performance for a scattered timeout pattern, so we don't want to
just switch the implementation.

This patch gives the user the ability to explicitly tag certain
timeout values as being "very common".  These timeout values have a
cookie encoded in the high bits of their tv_usec field to indicate
which queue they belong on.  The queues themselves are each
triggered by an entry in the minheap.

See the regress_main.c code for an example use.

svn:r1517
2009-11-09 17:16:30 +00:00
Nick Mathewson
a2a7d1d123 Do not call the locking variant of event_add or event_active in some cases when we know we have the lock.
svn:r1471
2009-10-27 05:16:32 +00:00
Nick Mathewson
b06b2649b4 Make "deferred callback queue" independent of event_base.
This way, we can more easily have an IOCP bufferevent implementation
that does not need an event_base at all.  Woot.

svn:r1381
2009-07-26 01:29:39 +00:00
Nick Mathewson
5d71b25b51 Remove all trailing whitespace from end-of-line.
svn:r1350
2009-07-17 18:38:38 +00:00
Nick Mathewson
6b4b77a265 Make event_del(E) block while E is running in another thread.
This gives you the property that once you have called event_del(E),
you know that E is no longer running or pending or active at all, and
so it is safe to delete the resource used by E's callback.

svn:r1341
2009-07-14 16:54:48 +00:00
Nick Mathewson
b4886ec80d Trim 22 bytes from struct event on 32 bit platforms, more on 64-bit platforms.
svn:r1292
2009-05-15 18:44:44 +00:00
Nick Mathewson
fe47003d06 Make unit tests for bufferevent_async compile and _almost_ work.
Either I need to make the callbacks get deferred in a base with no events (doable), or I need to make it okay to call launch_read from inside the callback for read (tricky).

svn:r1277
2009-05-05 16:52:37 +00:00
Nick Mathewson
b69d03b5a8 Add a constructor for bufferevent_async.
svn:r1274
2009-05-05 14:18:14 +00:00
Nick Mathewson
838d0a81c3 Document many internal functions and pieces of code.
svn:r1181
2009-04-17 06:55:08 +00:00
Nick Mathewson
4868f4d217 Initial support for a lightweight 'deferred callbacks'.
A 'deferred callback' is just a function that we've queued in the
event base.  This ability is needed for some mt stuff, and for complex
callback chains.  For internal use only.

svn:r1150
2009-04-10 14:22:33 +00:00
Nick Mathewson
ec35eb5520 Make threading functions global, like the mm_ functions. Use the libevent_pthread.la library in regress_pthread.
svn:r1121
2009-02-12 22:19:54 +00:00
Nick Mathewson
b85b710cf5 Update copyright statements to reflect the facts that:
a) this is 2009
b) niels and nick have been comaintainers for a while
c) saying "all rights reserved" when you then go on to explicitly
   disclaim some rights is sheer cargo-cultism.

svn:r1065
2009-01-27 22:34:36 +00:00
Nick Mathewson
8889a77039 Replace all use of config.h with event-config.h.
svn:r1064
2009-01-27 22:30:46 +00:00
Niels Provos
56ea4687a5 Change the semantics of timeouts in conjunction with EV_PERSIST; timeouts in that case will now repeat until deleted.
svn:r1032
2009-01-22 02:33:38 +00:00
Nick Mathewson
a5901991c7 Use eventfd for main-thread notification where available (i.e., linux).
svn:r1023
2009-01-19 20:37:24 +00:00
Nick Mathewson
554e14934e Move per-fd info from eventops into evmap. Not done for win32.c yet.
svn:r1008
2009-01-14 20:52:32 +00:00
Nick Mathewson
169321c9e6 Rename four internal headers to follow the -internal.h convention.
svn:r1000
2009-01-13 20:26:37 +00:00
Nick Mathewson
55bcd7d2f0 On win32, use a hashtable to map sockets to events rather than using an array.
svn:r988
2009-01-09 13:42:21 +00:00
Niels Provos
30cba6d0b3 we cannot realloc memory used by TAILQ; instead malloc each slot individually
svn:r977
2008-12-25 09:22:13 +00:00
Niels Provos
d776f8462b deprecate the usage of signal_{add,del,set} and name it evsignal_{add,del,set} instead; move the old definitions to compat
svn:r973
2008-12-23 22:23:37 +00:00
Niels Provos
02b2b4d1be Restructure the event backends so that they do not need to keep track of events themselves, as a side effect multiple events can use the same fd or signal.
svn:r972
2008-12-23 16:37:01 +00:00
Niels Provos
f7e61870e9 support multiple events listening on the same signal; make signals regular events that go on the same event queue
svn:r901
2008-07-11 15:49:04 +00:00
Nick Mathewson
05965921ab Add new functions to access backends by their features and to query the features of a backend.
svn:r842
2008-05-31 14:37:31 +00:00
Niels Provos
3f56e364b7 event_base_new_with_config() and related methods
svn:r789
2008-05-08 05:56:20 +00:00
Niels Provos
8c750eaff8 separate signal events from io events
svn:r760
2008-05-03 21:37:33 +00:00
Niels Provos
45e6fb0dd2 cache clock_gettime/gettimeofday values in base
svn:r758
2008-05-03 18:23:44 +00:00
Niels Provos
c182baca10 switch thread support so that locks get allocated as they are needed.
svn:r690
2008-03-10 03:17:20 +00:00
Niels Provos
558de9b377 Provide OpenSSL style support for multiple threads accessing the same event_base
svn:r684
2008-03-02 21:18:33 +00:00
Niels Provos
03589ccb12 rollback r594: restructuring to make event activation independent.
changes are going to wait for api design


svn:r612
2007-12-24 22:49:30 +00:00
Niels Provos
7aa845b73b restructure the code to make event activation independent of regular event logic
svn:r594
2007-12-16 04:10:30 +00:00
Niels Provos
fbe24f43ab remove obsoleted recalc code
svn:r581
2007-12-09 05:07:20 +00:00
Nick Mathewson
2823cb0579 r14944@tombo: nickm | 2007-11-25 12:12:28 -0500
Make kqueue pass more unit tests.


svn:r544
2007-11-25 17:15:28 +00:00
Nick Mathewson
7eb250e9c5 r14939@tombo: nickm | 2007-11-25 11:59:26 -0500
New function event_set_mem_functions to replace internal calls to malloc, free, etc with a user-supplied functions.


svn:r541
2007-11-25 17:14:19 +00:00
Niels Provos
88897852fc provide event_reinit() to reinitialized an event_base after fork - necessary for epoll/kqueue
svn:r539
2007-11-25 06:57:59 +00:00
Nick Mathewson
1c23e21952 r14931@tombo: nickm | 2007-11-17 17:21:09 -0500
Patch from Scott Lamb: Implement event_{base_}loopbreak.  Includes documentation and tests.  From sf.net Feature Request 1826546.


svn:r535
2007-11-17 22:21:42 +00:00
Nick Mathewson
f74e7258fd r16501@catbus: nickm | 2007-11-07 01:00:31 -0500
This is one of those patches which will either make matters far
 simpler after the bugs shake out, or will get reverted pretty quick
 once we realize that it is a stupid idea.
 
 We now post-process the config.h file into a new event-config.h file,
 whose macros are prefixed with _EVENT_ and which is thus safe for
 headers to include.  Using this, we can define replacement timeval
 manipulation functions in evutil.h, and use them uniformly through our
 code.  We can also detect which headers are needful in event.h, and
 include them as required.
 
 This is also the perfect time to remove the long-deprecated acconfig.h
 file, so that autoheader no longer warns.
 
 Should resolve the following issues:
 
 [ 1826530 ] Header files should have access to autoconf output.
 [ 1826545 ] acconfig.h is deprecated.
 [ 1826564 ] On some platforms, event.h can't be included alone.
 


svn:r492
2007-11-07 06:01:57 +00:00
Niels Provos
30ae40cc52 switch timeouts to a min heap; from Maxim Yegorushkin
svn:r467
2007-11-03 18:04:53 +00:00
Niels Provos
41b7cbc381 more the signal base into the event base; this removes global state and makes signals
work better with threading; from Wouter Wijngaards
small fixes for kqueue and style by me


svn:r351
2007-03-10 06:37:53 +00:00
Niels Provos
905ee67d00 provide maintainer mode in automake; put event_gotsig back into global
state; return proper error code


svn:r131
2005-02-22 15:47:53 +00:00
Niels Provos
8773c4c96c make libevent thread-safe; first cut
svn:r122
2004-11-25 09:50:18 +00:00