diff options
author | Volker Lendecke <vl@samba.org> | 2016-08-31 15:03:16 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2016-10-05 00:06:21 +0200 |
commit | c834efabd685198c570503bfc8394ff80899cef5 (patch) | |
tree | 7a275f675864b8b4697ff630c658904928d6ba88 /lib | |
parent | 85221cd882cd0622bdab30d60e7907e520019905 (diff) | |
download | samba-c834efabd685198c570503bfc8394ff80899cef5.tar.gz |
tevent: Factor out tevent_common_insert_timer
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tevent/tevent_timed.c | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/lib/tevent/tevent_timed.c b/lib/tevent/tevent_timed.c index 920d39fe063..bb0160c41e4 100644 --- a/lib/tevent/tevent_timed.c +++ b/lib/tevent/tevent_timed.c @@ -154,39 +154,13 @@ static int tevent_common_timed_deny_destructor(struct tevent_timer *te) return -1; } -/* - add a timed event - return NULL on failure (memory allocation error) -*/ -static struct tevent_timer *tevent_common_add_timer_internal( - struct tevent_context *ev, - TALLOC_CTX *mem_ctx, - struct timeval next_event, - tevent_timer_handler_t handler, - void *private_data, - const char *handler_name, - const char *location, - bool optimize_zero) +static void tevent_common_insert_timer(struct tevent_context *ev, + struct tevent_timer *te, + bool optimize_zero) { - struct tevent_timer *te, *prev_te, *cur_te; - - te = talloc(mem_ctx?mem_ctx:ev, struct tevent_timer); - if (te == NULL) return NULL; - - te->event_ctx = ev; - te->next_event = next_event; - te->handler = handler; - te->private_data = private_data; - te->handler_name = handler_name; - te->location = location; - te->additional_data = NULL; - - if (ev->timer_events == NULL) { - ev->last_zero_timer = NULL; - } + struct tevent_timer *prev_te = NULL; /* keep the list ordered */ - prev_te = NULL; if (optimize_zero && tevent_timeval_is_zero(&te->next_event)) { /* * Some callers use zero tevent_timer @@ -199,6 +173,8 @@ static struct tevent_timer *tevent_common_add_timer_internal( prev_te = ev->last_zero_timer; ev->last_zero_timer = te; } else { + struct tevent_timer *cur_te; + /* * we traverse the list from the tail * because it's much more likely that @@ -227,6 +203,40 @@ static struct tevent_timer *tevent_common_add_timer_internal( } DLIST_ADD_AFTER(ev->timer_events, te, prev_te); +} + +/* + add a timed event + return NULL on failure (memory allocation error) +*/ +static struct tevent_timer *tevent_common_add_timer_internal( + struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + struct timeval next_event, + tevent_timer_handler_t handler, + void *private_data, + const char *handler_name, + const char *location, + bool optimize_zero) +{ + struct tevent_timer *te; + + te = talloc(mem_ctx?mem_ctx:ev, struct tevent_timer); + if (te == NULL) return NULL; + + te->event_ctx = ev; + te->next_event = next_event; + te->handler = handler; + te->private_data = private_data; + te->handler_name = handler_name; + te->location = location; + te->additional_data = NULL; + + if (ev->timer_events == NULL) { + ev->last_zero_timer = NULL; + } + + tevent_common_insert_timer(ev, te, optimize_zero); talloc_set_destructor(te, tevent_common_timed_destructor); |