From e7d08f6539f6857c0dca604119986a872383e745 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Tue, 10 Dec 2024 16:21:24 -0800 Subject: [PATCH] test dispatch after --- source/darwin/dispatch_queue_event_loop.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/darwin/dispatch_queue_event_loop.c b/source/darwin/dispatch_queue_event_loop.c index 3aac8c18a..a0a634778 100644 --- a/source/darwin/dispatch_queue_event_loop.c +++ b/source/darwin/dispatch_queue_event_loop.c @@ -320,10 +320,6 @@ static void s_dispatch_queue_destroy_task(void *context) { static void s_destroy(struct aws_event_loop *event_loop) { AWS_LOGF_TRACE(AWS_LS_IO_EVENT_LOOP, "id=%p: Destroying Dispatch Queue Event Loop", (void *)event_loop); struct dispatch_loop *dispatch_loop = event_loop->impl_data; - /* Avoid double release on dispatch_loop */ - if (!dispatch_loop) { - return; - } /* make sure the loop is running so we can schedule a last task. */ s_run(event_loop); @@ -490,7 +486,7 @@ static void s_run_iteration(void *context) { /** * Checks if a new iteration task needs to be scheduled, given a target timestamp. If so, submits an iteration task to - * dispatch queue and registers the pending execution in the event loop's list of scheduled iterations. + * dispatch queue and registers the pending execution in the event loop's list of scheduled_services. * * If timestamp==0, the function will always schedule a new iteration as long as the event loop is not suspended. * @@ -505,7 +501,11 @@ static void s_try_schedule_new_iteration(struct dispatch_loop_context *dispatch_ } struct scheduled_service_entry *entry = s_scheduled_service_entry_new(dispatch_loop_context, timestamp); aws_linked_list_push_front(&dispatch_loop_context->scheduling_state.scheduled_services, &entry->node); - dispatch_async_f(dispatch_loop->dispatch_queue, entry, s_run_iteration); + + uint64_t now_ns = 0; + aws_event_loop_current_clock_time(dispatch_loop->base_loop, &now_ns); + uint64_t delta = timestamp == 0 ? 0 : timestamp - now_ns; + dispatch_after_f(delta, dispatch_loop->dispatch_queue, entry, s_run_iteration); } static void s_schedule_task_common(struct aws_event_loop *event_loop, struct aws_task *task, uint64_t run_at_nanos) {