diff options
author | Stefan Metzmacher <metze@samba.org> | 2007-05-04 09:22:52 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:51:58 -0500 |
commit | 6c6c5927a1e16e347a0e353904241694b21b57f9 (patch) | |
tree | 58b8a0d18f21ecd8f1565738cb829a8bfa555a42 /source4/lib/events/events_standard.c | |
parent | e4161f9deee8198e9128e88458e3c5603e86cd3e (diff) | |
download | samba-6c6c5927a1e16e347a0e353904241694b21b57f9.tar.gz samba-6c6c5927a1e16e347a0e353904241694b21b57f9.tar.bz2 samba-6c6c5927a1e16e347a0e353904241694b21b57f9.zip |
r22661: optimize the handling of directly triggered timed events:
- if someone adds a timed_event with a zero timeval
we now avoid serval gettimeofday() calls and the
event handler doesn't get the current time when it's
called, instead we also pass a zero timeval
- this also makes sure multiple timed events with a zero timeval
are processed in the order there're added.
the little benchmark shows that processing 2000000 directly timed events
is now much faster, while avoiding syscalls at all!
> time ./evtest (with the old code)
real 0m6.388s
user 0m1.740s
sys 0m4.632s
> time ./evtest (with the new code)
real 0m1.498s
user 0m1.496s
sys 0m0.004s
metze@SERNOX:~/devel/samba/4.0/samba4-ci/source> cat evtest.c
#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>
#include <talloc.h>
#include <events.h>
static void dummy_fde_handler(struct event_context *ev_ctx, struct fd_event *fde,
uint16_t flags, void *private_data)
{
}
static void timeout_handler(struct event_context *ev, struct timed_event *te,
struct timeval tval, void *private_data)
{
uint32_t *countp = (uint32_t *)private_data;
(*countp)++;
if (*countp > 2000000) exit(0);
event_add_timed(ev, ev, tval, timeout_handler, countp);
}
int main(void)
{
struct event_context *ev;
struct timeval tval = { 0, 0 };
uint32_t count = 0;
ev = event_context_init(NULL);
event_add_fd(ev, ev, 0, 0, dummy_fde_handler, NULL);
event_add_timed(ev, ev, tval, timeout_handler, &count);
return event_loop_wait(ev);
}
(This used to be commit 4db64b4ce2320b88d648078cbf86385f6fb44f1f)
Diffstat (limited to 'source4/lib/events/events_standard.c')
-rw-r--r-- | source4/lib/events/events_standard.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/source4/lib/events/events_standard.c b/source4/lib/events/events_standard.c index 8495ccdec0..dcf890ac12 100644 --- a/source4/lib/events/events_standard.c +++ b/source4/lib/events/events_standard.c @@ -248,7 +248,8 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv } if (ret == 0 && tvalp) { - common_event_loop_timer(std_ev->ev); + /* we don't care about a possible delay here */ + common_event_loop_timer_delay(std_ev->ev); return 0; } @@ -471,7 +472,8 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva } if (selrtn == 0 && tvalp) { - common_event_loop_timer(std_ev->ev); + /* we don't care about a possible delay here */ + common_event_loop_timer_delay(std_ev->ev); return 0; } @@ -505,10 +507,8 @@ static int std_event_loop_once(struct event_context *ev) struct std_event_context); struct timeval tval; - tval = common_event_loop_delay(ev); - + tval = common_event_loop_timer_delay(ev); if (timeval_is_zero(&tval)) { - common_event_loop_timer(ev); return 0; } |