Skip to content

Commit

Permalink
quick dispatch queue test
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazhvera committed Jan 21, 2025
1 parent 0397c14 commit aabba3c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
12 changes: 9 additions & 3 deletions source/darwin/dispatch_queue_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,11 @@ static int s_run(struct aws_event_loop *event_loop) {
dispatch_resume(dispatch_loop->dispatch_queue);
dispatch_loop->synced_data.suspended = false;
s_rlock_dispatch_loop_context(dispatch_loop->context);
s_lock_service_entries(dispatch_loop->context);
s_try_schedule_new_iteration(dispatch_loop->context, 0);
s_unlock_service_entries(dispatch_loop->context);
if (dispatch_loop->context->io_dispatch_loop) {
s_lock_service_entries(dispatch_loop->context);
s_try_schedule_new_iteration(dispatch_loop->context, 0);
s_unlock_service_entries(dispatch_loop->context);
}
s_runlock_dispatch_loop_context(dispatch_loop->context);
}
s_unlock_cross_thread_data(dispatch_loop);
Expand Down Expand Up @@ -618,6 +620,9 @@ static void s_schedule_task_common(struct aws_event_loop *event_loop, struct aws
struct dispatch_loop *dispatch_loop = event_loop->impl_data;

s_rlock_dispatch_loop_context(dispatch_loop->context);
if (dispatch_loop->context->io_dispatch_loop == NULL) {
goto schedule_task_common_cleanup;
}
s_lock_cross_thread_data(dispatch_loop);
task->timestamp = run_at_nanos;

Expand Down Expand Up @@ -653,6 +658,7 @@ static void s_schedule_task_common(struct aws_event_loop *event_loop, struct aws
}

s_unlock_cross_thread_data(dispatch_loop);
schedule_task_common_cleanup:
s_runlock_dispatch_loop_context(dispatch_loop->context);
}

Expand Down
36 changes: 21 additions & 15 deletions source/darwin/nw_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,22 +1388,28 @@ static int s_socket_start_accept_fn(
(void *)socket,
(void *)nw_socket->nw_connection);

struct aws_task *task = aws_mem_calloc(socket->allocator, 1, sizeof(struct aws_task));

struct nw_socket_scheduled_task_args *args =
aws_mem_calloc(socket->allocator, 1, sizeof(struct nw_socket_scheduled_task_args));

args->nw_socket = nw_socket;
args->allocator = nw_socket->allocator;
// acquire ref count for the task
nw_socket_acquire_internal_ref(nw_socket);
AWS_LOGF_DEBUG(
AWS_LS_IO_SOCKET,
"id=%p: nw_socket_acquire_internal_ref: s_process_set_listener_endpoint_task",
(void *)nw_socket);
// TODO: revisit
aws_mutex_lock(&nw_socket->synced_data.lock);
if (nw_socket->synced_data.event_loop) {
struct aws_task *task = aws_mem_calloc(socket->allocator, 1, sizeof(struct aws_task));

struct nw_socket_scheduled_task_args *args =
aws_mem_calloc(socket->allocator, 1, sizeof(struct nw_socket_scheduled_task_args));

args->nw_socket = nw_socket;
args->allocator = nw_socket->allocator;
// acquire ref count for the task
nw_socket_acquire_internal_ref(nw_socket);
AWS_LOGF_DEBUG(
AWS_LS_IO_SOCKET,
"id=%p: nw_socket_acquire_internal_ref: s_process_set_listener_endpoint_task",
(void *)nw_socket);

aws_task_init(task, s_process_set_listener_endpoint_task, args, "listenerSuccessTask");
aws_event_loop_schedule_task_now(socket->event_loop, task);
aws_task_init(task, s_process_set_listener_endpoint_task, args, "listenerSuccessTask");
// TODO: what if event loop is shuting down & what happened if we schedule the task here.
aws_event_loop_schedule_task_now(socket->event_loop, task);
}
aws_mutex_unlock(&nw_socket->synced_data.lock);

} else if (state == nw_listener_state_cancelled) {
AWS_LOGF_DEBUG(
Expand Down

0 comments on commit aabba3c

Please sign in to comment.