From f9caed47f6d88c85e1f1ce74df7a7ed52ade10b6 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 16 Dec 2024 13:19:04 -0800 Subject: [PATCH] clean up begin_iteration --- source/darwin/dispatch_queue_event_loop.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/darwin/dispatch_queue_event_loop.c b/source/darwin/dispatch_queue_event_loop.c index 6647923d0..71e20f88c 100644 --- a/source/darwin/dispatch_queue_event_loop.c +++ b/source/darwin/dispatch_queue_event_loop.c @@ -377,12 +377,12 @@ static int s_stop(struct aws_event_loop *event_loop) { // returns true if we should execute an iteration, false otherwise // The function should be wrapped with dispatch_loop->context.lock static bool begin_iteration(struct scheduled_service_entry *entry) { - bool should_execute_iteration = false; struct dispatch_loop *dispatch_loop = entry->dispatch_queue_context->io_dispatch_loop; - aws_linked_list_remove(&entry->node); - should_execute_iteration = true; - return should_execute_iteration; + if (!dispatch_loop) { + return false; + } + return true; } // conditionally schedule another iteration as needed @@ -423,14 +423,14 @@ static void s_run_iteration(void *context) { struct scheduled_service_entry *entry = context; struct dispatch_loop_context *dispatch_queue_context = entry->dispatch_queue_context; s_rlock_dispatch_loop_context(dispatch_queue_context); - struct dispatch_loop *dispatch_loop = entry->dispatch_queue_context->io_dispatch_loop; + // Removed and clean up the service entry regardless if the iteration run or not. + aws_linked_list_remove(&entry->node); - if (!dispatch_loop) { + if (!begin_iteration(entry)) { goto iteration_done; } - begin_iteration(entry); - + struct dispatch_loop *dispatch_loop = entry->dispatch_queue_context->io_dispatch_loop; // swap the cross-thread tasks into task-local data struct aws_linked_list local_cross_thread_tasks; aws_linked_list_init(&local_cross_thread_tasks);