From 788187c0309bf3bfcc7e056a3d78c2f4c2df7588 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 23 Oct 2014 07:15:14 +0200 Subject: [PATCH] tevent: use struct initializers for tevent_immediate Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- lib/tevent/tevent_immediate.c | 30 ++++++++++++++++-------------- lib/tevent/tevent_threads.c | 16 +++++++++------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/tevent/tevent_immediate.c b/lib/tevent/tevent_immediate.c index 9ff53223430..7b4c3e843de 100644 --- a/lib/tevent/tevent_immediate.c +++ b/lib/tevent/tevent_immediate.c @@ -30,6 +30,8 @@ static void tevent_common_immediate_cancel(struct tevent_immediate *im) { + const char *create_location = im->create_location; + if (!im->event_ctx) { return; } @@ -44,13 +46,10 @@ static void tevent_common_immediate_cancel(struct tevent_immediate *im) } DLIST_REMOVE(im->event_ctx->immediate_events, im); - im->event_ctx = NULL; - im->handler = NULL; - im->private_data = NULL; - im->handler_name = NULL; - im->schedule_location = NULL; - im->cancel_fn = NULL; - im->additional_data = NULL; + + *im = (struct tevent_immediate) { + .create_location = create_location, + }; talloc_set_destructor(im, NULL); } @@ -74,19 +73,22 @@ void tevent_common_schedule_immediate(struct tevent_immediate *im, const char *handler_name, const char *location) { + const char *create_location = im->create_location; + tevent_common_immediate_cancel(im); if (!handler) { return; } - im->event_ctx = ev; - im->handler = handler; - im->private_data = private_data; - im->handler_name = handler_name; - im->schedule_location = location; - im->cancel_fn = NULL; - im->additional_data = NULL; + *im = (struct tevent_immediate) { + .event_ctx = ev, + .handler = handler, + .private_data = private_data, + .handler_name = handler_name, + .create_location = create_location, + .schedule_location = location, + }; DLIST_ADD_END(ev->immediate_events, im); talloc_set_destructor(im, tevent_common_immediate_destructor); diff --git a/lib/tevent/tevent_threads.c b/lib/tevent/tevent_threads.c index 2c6e66b0904..728f8416d45 100644 --- a/lib/tevent/tevent_threads.c +++ b/lib/tevent/tevent_threads.c @@ -449,6 +449,7 @@ void _tevent_threaded_schedule_immediate(struct tevent_threaded_context *tctx, const char *location) { #ifdef HAVE_PTHREAD + const char *create_location = im->create_location; struct tevent_context *ev; int ret, wakeup_fd; @@ -474,13 +475,14 @@ void _tevent_threaded_schedule_immediate(struct tevent_threaded_context *tctx, abort(); } - im->event_ctx = ev; - im->handler = handler; - im->private_data = private_data; - im->handler_name = handler_name; - im->schedule_location = location; - im->cancel_fn = NULL; - im->additional_data = NULL; + *im = (struct tevent_immediate) { + .event_ctx = ev, + .handler = handler, + .private_data = private_data, + .handler_name = handler_name, + .create_location = create_location, + .schedule_location = location, + }; ret = pthread_mutex_lock(&ev->scheduled_mutex); if (ret != 0) { -- 2.47.3