Nick Mathewson [Thu, 19 Apr 2012 04:25:12 +0000 (00:25 -0400)]
If time has jumped so we'd reschedule a periodic event in the past, schedule it for the future instead
Fixes an issue reported on libevent-users in the thread "a dead
looping bug when changing system time backward". Previously, if time
jumped forward 1 hour[*] and we had a one-second periodic timer event,
that event would get invoked 3600 times. That's almost certainly not
what anybody wants.
In a future version of Libevent, we should expose the amount of time
that the callbac kwould have been invoked somehow.
[*] Forward time jumps can happen with nonmonotonic clocks, or with
clocks that jump on suspend/resume. It can also happen from
Libevent's point of view if the user exits from event_base_loop() and
doesn't call it again for a while.
Nick Mathewson [Tue, 17 Apr 2012 17:04:02 +0000 (13:04 -0400)]
EVENT_BASE_FLAG_PRECISE_TIMER indicates we want fine timer precision
There are a bunch of backends that can give us a reasonably good
monotonic timer quickly, or a very precise monotonic timer less
quickly. For example, Linux has CLOCK_MONOTONIC_COARSE (1msec
precision), which is over twice as fast as CLOCK_MONOTONIC. Since
epoll only lets you wait with 1msec precision,
CLOCK_MONOTONIC_COARSE is a clear win.
On Windows, you've got GetTickCount{,64}() which is fast, and
QueryPerformanceCounter, which is precise but slow.
Note that even in the cases where the underlying timer claims to
have nanosecond resolution, we're still not exposing that via
Libevent.
Note also that "Precision" isn't the same as "Resolution" or
"Accuracy". A timer's precision is the smallest change that the
clock will register; a timer's resolution is the fineness of its
underlying representation; a timer's accuracy is how much it drifts
with respect to "Real Time", whatever that means. (Terms and
definitions from PEP 418.)
Nick Mathewson [Tue, 17 Apr 2012 16:44:39 +0000 (12:44 -0400)]
Move use_monotonic and friends into event_base
The use_monotonic field used to be a static field set up at library
setup. Unfortunately, this makes it hard to give the user a way to
make speed/accuracy tradeoffs about time. Moving it into event_base
should let the clock implementation become configurable.
Nick Mathewson [Fri, 17 Sep 2010 04:34:13 +0000 (00:34 -0400)]
Replace pipe-based notification with EVFILT_USER where possible
Sufficiently recent kqueue implementations have an EVFILT_USER filter
that we can use to wake up an event base from another thread. When
it's supported, we now use this mechanism rather than our old
(pipe-based) mechanism. This should save some time and complications
on newer OSX and freebsds.
Change evutil_weakrand_() to avoid platform random()
This change allows us to avoid perturbing the platform's random(), and
to avoid hitting locks on random() in the platform's libc.
evutil_weakrand_() is, well, weak, so we choose here an algorithm that
favors speed over a number of other possibly desirable properties.
We're using a linear congruential generator, and taking our parameters
from those shared by the OpenBSD random() implementation, and
Glibc's fastest random() implementation.
The low bits of a LCG of modulus 2^32 are (notoriously) less random
than the higher bits. So to generate a random value in a range, using
the % operator is no good; we ought to divide. We add an
evutil_weakrand_range_() function to do that.
This code also changes the interface of evutil_weakrand_() so that it
now manipulates an explicit seed, rather than having the seed in a
static variable. This change enables us to use existing locks to
achieve thread-safety, rather than having to rely on an additional lock.
(Patch by Nicholas Marriott; commit message by Nick Mathewson.)
Nick Mathewson [Tue, 3 Apr 2012 22:31:08 +0000 (18:31 -0400)]
Backport: provide EVENT_LOG_* names, and deprecate _EVENT_LOG_*
This is a partial backport of cb9da0bf and a backport of c9635349.
Because C doesn't like us to declare identifiers starting with an
underscore, Libevent 2.1 has renamed every such identifier. The
only change that affects a public API is that the _EVENT_LOG_*
macros have been renamed to start with EVENT_LOG instead. The old
names are still present, but deprecated.
I'm doing this backport because it represents the deprecation of a
Libevent 2.0 interface, and folks should have the opportunity to
write code that isn't deprecated and works with both 2.0 and 2.1.
Nick Mathewson [Sun, 1 Apr 2012 04:21:55 +0000 (00:21 -0400)]
Increase duration and tolerance on http/connection_retry test
This takes its runtime back up a little again, but not so high as it
was before. It appears to address the heisenbug issues of github
nmathewson/libevent issue #49. So far.
Nick Mathewson [Tue, 27 Mar 2012 03:28:21 +0000 (23:28 -0400)]
Temporarily disable event_queue_reinsert_timeout
Apparently, now that we have tests for it in main/common_timeout, we
can now see that it sometimes breaks referential integrity somehow.
Since I'd like to get 2.1.1-alpha out the door soon, I'm turning it
off for now.
Nick Mathewson [Fri, 23 Mar 2012 22:42:56 +0000 (18:42 -0400)]
Fix a nasty bug in event_queue_reinsert_timeout()
What was I thinking? The old function could handle heap-to-heap
transitions, and transitions within the same common timeout queue, but
it completely failed to handle heap/queue transitions, or transitions
between timeout queues.
Now, alas, it's complicated. I should look hard at the assembly here
to see if it's actually better than the alternatives.
Nick Mathewson [Fri, 23 Mar 2012 21:56:23 +0000 (17:56 -0400)]
Add a unit test for event_base_dump_events()
This function uses a C program to generate its output, and then uses a
Python program to check it for correctness. On systems without
Python, we just make sure that the C program doesn't crash.
It's likely that we should be requiring some particular python version.
This is an alpha, though: I'm sure somebody will tell us which.
- rename the function to emphasize that it's for global resources
- write more in the doxygen
- make function brace style consistent
- add a missing void in a function definition.