tevent: use _tevent_schedule_immediate() to move events from a thread to the main_ev
authorStefan Metzmacher <metze@samba.org>
Fri, 23 Mar 2018 09:25:27 +0000 (10:25 +0100)
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 7b4c3e843deddea80608f2935bdb379de725c5f0..c640a565b08250b0269dddfb9c19a7e136c500ea 100644 (file)
@@ -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) {
index 728f8416d4527c88b0713a2d9e30c2f95c2cf227..3f91ab8bc2abf01957526f6dba204c2edb2bc092 100644 (file)
@@ -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);