@@ -31,6 +31,7 @@ static int s_run(struct aws_event_loop *event_loop);
3131static int s_stop (struct aws_event_loop * event_loop );
3232static int s_wait_for_stop_completion (struct aws_event_loop * event_loop );
3333static void s_schedule_task_now (struct aws_event_loop * event_loop , struct aws_task * task );
34+ static void s_schedule_task_now_serialized (struct aws_event_loop * event_loop , struct aws_task * task );
3435static void s_schedule_task_future (struct aws_event_loop * event_loop , struct aws_task * task , uint64_t run_at_nanos );
3536static void s_cancel_task (struct aws_event_loop * event_loop , struct aws_task * task );
3637static int s_connect_to_io_completion_port (struct aws_event_loop * event_loop , struct aws_io_handle * handle ) {
@@ -134,6 +135,7 @@ struct aws_event_loop_vtable s_kqueue_vtable = {
134135 .stop = s_stop ,
135136 .wait_for_stop_completion = s_wait_for_stop_completion ,
136137 .schedule_task_now = s_schedule_task_now ,
138+ .schedule_task_now_serialized = s_schedule_task_now_serialized ,
137139 .schedule_task_future = s_schedule_task_future ,
138140 .cancel_task = s_cancel_task ,
139141 .connect_to_io_completion_port = s_connect_to_io_completion_port ,
@@ -465,29 +467,12 @@ static int s_wait_for_stop_completion(struct aws_event_loop *event_loop) {
465467 return AWS_OP_SUCCESS ;
466468}
467469
468- /* Common functionality for "now" and "future" task scheduling.
469- * If `run_at_nanos` is zero then the task is scheduled as a "now" task. */
470- static void s_schedule_task_common ( struct aws_event_loop * event_loop , struct aws_task * task , uint64_t run_at_nanos ) {
471- AWS_ASSERT ( task );
470+ static void s_schedule_task_cross_thread (
471+ struct aws_event_loop * event_loop ,
472+ struct aws_task * task ,
473+ uint64_t run_at_nanos ) {
472474 struct kqueue_loop * impl = event_loop -> impl_data ;
473475
474- /* If we're on the event-thread, just schedule it directly */
475- if (s_is_event_thread (event_loop )) {
476- AWS_LOGF_TRACE (
477- AWS_LS_IO_EVENT_LOOP ,
478- "id=%p: scheduling task %p in-thread for timestamp %llu" ,
479- (void * )event_loop ,
480- (void * )task ,
481- (unsigned long long )run_at_nanos );
482- if (run_at_nanos == 0 ) {
483- aws_task_scheduler_schedule_now (& impl -> thread_data .scheduler , task );
484- } else {
485- aws_task_scheduler_schedule_future (& impl -> thread_data .scheduler , task , run_at_nanos );
486- }
487- return ;
488- }
489-
490- /* Otherwise, add it to cross_thread_data.tasks_to_schedule and signal the event-thread to process it */
491476 AWS_LOGF_TRACE (
492477 AWS_LS_IO_EVENT_LOOP ,
493478 "id=%p: scheduling task %p cross-thread for timestamp %llu" ,
@@ -515,10 +500,40 @@ static void s_schedule_task_common(struct aws_event_loop *event_loop, struct aws
515500 }
516501}
517502
503+ /* Common functionality for "now" and "future" task scheduling.
504+ * If `run_at_nanos` is zero then the task is scheduled as a "now" task. */
505+ static void s_schedule_task_common (struct aws_event_loop * event_loop , struct aws_task * task , uint64_t run_at_nanos ) {
506+ AWS_ASSERT (task );
507+ struct kqueue_loop * impl = event_loop -> impl_data ;
508+
509+ /* If we're on the event-thread, just schedule it directly */
510+ if (s_is_event_thread (event_loop )) {
511+ AWS_LOGF_TRACE (
512+ AWS_LS_IO_EVENT_LOOP ,
513+ "id=%p: scheduling task %p in-thread for timestamp %llu" ,
514+ (void * )event_loop ,
515+ (void * )task ,
516+ (unsigned long long )run_at_nanos );
517+ if (run_at_nanos == 0 ) {
518+ aws_task_scheduler_schedule_now (& impl -> thread_data .scheduler , task );
519+ } else {
520+ aws_task_scheduler_schedule_future (& impl -> thread_data .scheduler , task , run_at_nanos );
521+ }
522+ return ;
523+ }
524+
525+ /* Otherwise, add it to cross_thread_data.tasks_to_schedule and signal the event-thread to process it */
526+ s_schedule_task_cross_thread (event_loop , task , run_at_nanos );
527+ }
528+
518529static void s_schedule_task_now (struct aws_event_loop * event_loop , struct aws_task * task ) {
519530 s_schedule_task_common (event_loop , task , 0 ); /* Zero is used to denote "now" tasks */
520531}
521532
533+ static void s_schedule_task_now_serialized (struct aws_event_loop * event_loop , struct aws_task * task ) {
534+ s_schedule_task_cross_thread (event_loop , task , 0 ); /* Zero is used to denote "now" tasks */
535+ }
536+
522537static void s_schedule_task_future (struct aws_event_loop * event_loop , struct aws_task * task , uint64_t run_at_nanos ) {
523538 s_schedule_task_common (event_loop , task , run_at_nanos );
524539}
0 commit comments