Skip to content

Commit

Permalink
Merge branch 'grand_dispatch_queue' of github.com:awslabs/aws-c-io in…
Browse files Browse the repository at this point in the history
…to nw_socket
  • Loading branch information
xiazhvera committed Sep 17, 2024
2 parents 731ba49 + 5ab8f24 commit bac8b07
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ option(BUILD_RELOCATABLE_BINARIES
OFF)
option(BYO_CRYPTO "Don't build a tls implementation or link against a crypto interface. This feature is only for unix builds currently."
OFF)
# DEBUG: directly set AWS_USE_DISPATCH_QUEUE
set (AWS_USE_DISPATCH_QUEUE ON)

file(GLOB AWS_IO_HEADERS
"include/aws/io/*.h"
Expand Down Expand Up @@ -116,7 +118,8 @@ elseif (APPLE)
file(GLOB AWS_IO_OS_SRC
"source/bsd/*.c"
"source/posix/*.c"
"source/darwin/*.c"
"source/darwin/darwin_pki_utils.c"
"source/darwin/secure_transport_tls_channel_handler.c"
)

find_library(SECURITY_LIB Security)
Expand All @@ -132,8 +135,16 @@ elseif (APPLE)
#No choice on TLS for apple, darwinssl will always be used.
list(APPEND PLATFORM_LIBS "-framework Security -framework Network")

# DEBUG WIP We will add a check here to use kqueue queue for macOS and dispatch queue for iOS
set(EVENT_LOOP_DEFINES "-DAWS_USE_DISPATCH_QUEUE -DAWS_USE_KQUEUE")
if(AWS_USE_DISPATCH_QUEUE OR IOS)
set(EVENT_LOOP_DEFINES "-DAWS_USE_DISPATCH_QUEUE" )
message("use dispatch queue")
file(GLOB AWS_IO_DISPATCH_QUEUE_SRC
"source/darwin/dispatch_queue_event_loop.c"
)
list(APPEND AWS_IO_OS_SRC ${AWS_IO_DISPATCH_QUEUE_SRC})
else ()
set(EVENT_LOOP_DEFINES "-DAWS_USE_KQUEUE")
endif()

elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
file(GLOB AWS_IO_OS_HEADERS
Expand Down
4 changes: 1 addition & 3 deletions include/aws/io/event_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,14 @@ struct aws_overlapped {
void *user_data;
};

#else /* !AWS_USE_IO_COMPLETION_PORTS */
#endif /* AWS_USE_IO_COMPLETION_PORTS */

typedef void(aws_event_loop_on_event_fn)(
struct aws_event_loop *event_loop,
struct aws_io_handle *handle,
int events,
void *user_data);

#endif /* AWS_USE_IO_COMPLETION_PORTS */

enum aws_event_loop_style {
AWS_EVENT_LOOP_STYLE_UNDEFINED = 0,
AWS_EVENT_LOOP_STYLE_POLL_BASED = 1,
Expand Down
2 changes: 1 addition & 1 deletion include/aws/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ AWS_PUSH_SANE_WARNING_LEVEL

struct aws_io_handle;

#if AWS_USE_DISPATCH_QUEUE
#ifdef AWS_USE_DISPATCH_QUEUE
typedef void aws_io_set_queue_on_handle_fn(struct aws_io_handle *handle, void *queue);
typedef void aws_io_clear_queue_on_handle_fn(struct aws_io_handle *handle);
#endif /* AWS_USE_DISPATCH_QUEUE */
Expand Down
12 changes: 1 addition & 11 deletions source/darwin/dispatch_queue_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,6 @@ bool should_schedule_iteration(struct aws_linked_list *scheduled_iterations, uin
return entry->timestamp > proposed_iteration_time;
}

static void s_finalize(void *context) {
struct aws_event_loop *event_loop = context;
struct dispatch_loop *dispatch_loop = event_loop->impl_data;
AWS_LOGF_INFO(AWS_LS_IO_EVENT_LOOP, "id=%p: Dispatch Queue Finalized", (void *)event_loop);
aws_ref_count_release(&dispatch_loop->ref_count);
}

static void s_dispatch_event_loop_destroy(void *context) {
// release dispatch loop

Expand Down Expand Up @@ -186,10 +179,6 @@ struct aws_event_loop *aws_event_loop_new_dispatch_queue_with_options(
loop->impl_data = dispatch_loop;
loop->vtable = &s_vtable;

dispatch_set_context(dispatch_loop->dispatch_queue, loop);
// Definalizer will be called on dispatch queue ref drop to 0
dispatch_set_finalizer_f(dispatch_loop->dispatch_queue, &s_finalize);

// manually increament the thread count, so the library will wait for dispatch queue releasing
aws_thread_increment_unjoined_count();

Expand Down Expand Up @@ -410,6 +399,7 @@ static void s_schedule_task_common(struct aws_event_loop *event_loop, struct aws
bool should_schedule = false;

bool is_empty = aws_linked_list_empty(&dispatch_loop->synced_data.cross_thread_tasks);
task->timestamp = run_at_nanos;

// We dont have control to dispatch queue thread, threat all tasks are threated as cross thread tasks
aws_linked_list_push_back(&dispatch_loop->synced_data.cross_thread_tasks, &task->node);
Expand Down
2 changes: 1 addition & 1 deletion source/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static const struct aws_event_loop_configuration s_available_configurations[] =
.style = AWS_EVENT_LOOP_STYLE_COMPLETION_PORT_BASED,
},
#endif
#if TARGET_OS_IOS || AWS_USE_DISPATCH_QUEUE
#if AWS_USE_DISPATCH_QUEUE
/* use kqueue on OSX and dispatch_queues everywhere else */
{
.name = "Apple Dispatch Queue",
Expand Down
4 changes: 2 additions & 2 deletions source/windows/iocp/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ int aws_pipe_init(
}
}

int err = aws_event_loop_connect_handle_to_io_completion_port(write_end_event_loop, &write_impl->handle);
int err = aws_event_loop_connect_handle_to_completion_port(write_end_event_loop, &write_impl->handle);
if (err) {
goto clean_up;
}
Expand Down Expand Up @@ -282,7 +282,7 @@ int aws_pipe_init(
goto clean_up;
}

err = aws_event_loop_connect_handle_to_io_completion_port(read_end_event_loop, &read_impl->handle);
err = aws_event_loop_connect_handle_to_completion_port(read_end_event_loop, &read_impl->handle);
if (err) {
goto clean_up;
}
Expand Down
2 changes: 1 addition & 1 deletion source/windows/iocp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -2555,7 +2555,7 @@ int aws_socket_assign_to_event_loop(struct aws_socket *socket, struct aws_event_
}

socket->event_loop = event_loop;
return aws_event_loop_connect_handle_to_io_completion_port(event_loop, &socket->io_handle);
return aws_event_loop_connect_handle_to_completion_port(event_loop, &socket->io_handle);
}

struct aws_event_loop *aws_socket_get_event_loop(struct aws_socket *socket) {
Expand Down
4 changes: 2 additions & 2 deletions tests/event_loop_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static int s_test_event_loop_completion_events(struct aws_allocator *allocator,
ASSERT_SUCCESS(s_async_pipe_init(&read_handle, &write_handle));

/* Connect to event-loop */
ASSERT_SUCCESS(aws_event_loop_connect_handle_to_io_completion_port(event_loop, &write_handle));
ASSERT_SUCCESS(aws_event_loop_connect_handle_to_completion_port(event_loop, &write_handle));

/* Set up an async (overlapped) write that will result in s_on_overlapped_operation_complete() getting run
* and filling out `completion_data` */
Expand Down Expand Up @@ -1057,7 +1057,7 @@ static int s_event_loop_test_multiple_stops(struct aws_allocator *allocator, voi

ASSERT_NOT_NULL(event_loop, "Event loop creation failed with error: %s", aws_error_debug_str(aws_last_error()));
ASSERT_SUCCESS(aws_event_loop_run(event_loop));
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 8; ++j) {
ASSERT_SUCCESS(aws_event_loop_stop(event_loop));
}
aws_event_loop_destroy(event_loop);
Expand Down

0 comments on commit bac8b07

Please sign in to comment.