From 0b91f6f0e4eeff7bbff24b33dd2087e2903e969b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 23 Mar 2018 10:25:27 +0100 Subject: [PATCH] tevent: use _tevent_schedule_immediate() to move events from a thread to the main_ev Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- lib/tevent/tevent_immediate.c | 8 +++++--- lib/tevent/tevent_threads.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/tevent/tevent_immediate.c b/lib/tevent/tevent_immediate.c index 7b4c3e843de..c640a565b08 100644 --- a/lib/tevent/tevent_immediate.c +++ b/lib/tevent/tevent_immediate.c @@ -36,9 +36,11 @@ static void tevent_common_immediate_cancel(struct tevent_immediate *im) return; } - tevent_debug(im->event_ctx, TEVENT_DEBUG_TRACE, - "Cancel immediate event %p \"%s\"\n", - im, im->handler_name); + if (im->handler_name != NULL) { + tevent_debug(im->event_ctx, TEVENT_DEBUG_TRACE, + "Cancel immediate event %p \"%s\"\n", + im, im->handler_name); + } /* let the backend free im->additional_data */ if (im->cancel_fn) { diff --git a/lib/tevent/tevent_threads.c b/lib/tevent/tevent_threads.c index 728f8416d45..3f91ab8bc2a 100644 --- a/lib/tevent/tevent_threads.c +++ b/lib/tevent/tevent_threads.c @@ -532,8 +532,20 @@ void tevent_common_threaded_activate_immediate(struct tevent_context *ev) while (ev->scheduled_immediates != NULL) { struct tevent_immediate *im = ev->scheduled_immediates; + struct tevent_immediate copy = *im; + DLIST_REMOVE(ev->scheduled_immediates, im); - DLIST_ADD_END(ev->immediate_events, im); + + tevent_debug(ev, TEVENT_DEBUG_TRACE, + "Schedule immediate event \"%s\": %p from thread into main\n", + im->handler_name, im); + im->handler_name = NULL; + _tevent_schedule_immediate(im, + ev, + copy.handler, + copy.private_data, + copy.handler_name, + copy.schedule_location); } ret = pthread_mutex_unlock(&ev->scheduled_mutex); -- 2.34.1