tevent: use struct initializers for tevent_immediate
authorStefan Metzmacher <metze@samba.org>
Thu, 23 Oct 2014 05:15:14 +0000 (07:15 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 17 May 2018 07:51:46 +0000 (09:51 +0200)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
lib/tevent/tevent_immediate.c
lib/tevent/tevent_threads.c

index 9ff53223430630525fbc1a4b02f41d4d4b7fa17f..7b4c3e843deddea80608f2935bdb379de725c5f0 100644 (file)
@@ -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);
index 2c6e66b09049fe4a2ade8abed8a389f53996e9e0..728f8416d4527c88b0713a2d9e30c2f95c2cf227 100644 (file)
@@ -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) {