Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grand dispatch queue #661

Open
wants to merge 78 commits into
base: runtime_select_event_loop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
9389f14
CMakeLists.txt
sbSteveK Jul 29, 2024
e825924
event_loop.h
sbSteveK Jul 29, 2024
452217c
io.h
sbSteveK Jul 29, 2024
c0d4086
kqueue_event_loop.c
sbSteveK Jul 29, 2024
84fd773
dispatch_queue_event_loop.c
sbSteveK Jul 29, 2024
98c8ef0
event_loop.c
sbSteveK Jul 29, 2024
89e8ece
epoll_event_loop.c
sbSteveK Jul 29, 2024
9c27144
iocp_event_loop.c
sbSteveK Jul 29, 2024
f375bb2
event_loop_test.c
sbSteveK Jul 29, 2024
41a5fa1
try ifdef on TargetConditionals.h and comment failing event loop test
sbSteveK Jul 29, 2024
04c2b93
reorder the event loop config, so apple platform would use dispatch q…
xiazhvera Jul 30, 2024
0d301d2
bring in dispatch queue changes
xiazhvera Sep 3, 2024
4afaea6
clangformat
xiazhvera Sep 3, 2024
a7f6904
remove unused args
xiazhvera Sep 3, 2024
89635db
clean up
xiazhvera Sep 11, 2024
195ca1c
clean up dispatch queue
xiazhvera Sep 11, 2024
24ce65b
Merge branch 'main' of https://github.com/awslabs/aws-c-io into grand…
xiazhvera Sep 11, 2024
287094f
clang-format
xiazhvera Sep 11, 2024
bd58da0
more comments and format clean up
xiazhvera Sep 11, 2024
f0e5dde
quick windows test
xiazhvera Sep 16, 2024
aef1b14
TEST: quick error verification
xiazhvera Sep 16, 2024
41bb257
Revert "TEST: quick error verification"
xiazhvera Sep 16, 2024
22e68b2
TEST: using struct instead of union
xiazhvera Sep 16, 2024
a28cb37
Revert "TEST: using struct instead of union"
xiazhvera Sep 16, 2024
c67e966
add back definition for union
xiazhvera Sep 16, 2024
3ca34ce
WINDOWS: rename function
xiazhvera Sep 16, 2024
f8c26f5
fix compile error
xiazhvera Sep 16, 2024
a428cd8
remove unused finalize functions
xiazhvera Sep 16, 2024
5ab8f24
fix event loop schedule future
xiazhvera Sep 16, 2024
0918e76
improve dispatch caller's thread check
xiazhvera Sep 26, 2024
a55f14f
update caller's thread changes
xiazhvera Sep 26, 2024
06fb206
use lock to protect the thread id info
xiazhvera Sep 26, 2024
ed04764
lint
xiazhvera Sep 26, 2024
e8fe46d
fix thread related test/disable pipe tests
xiazhvera Sep 26, 2024
a84cb5a
AWS_USE_DISPATCH_QUEUE updates (#679)
sbSteveK Oct 3, 2024
977bb8a
Merge branch 'main' into grand_dispatch_queue
xiazhvera Oct 15, 2024
ce07c5a
bring in event loop changes
xiazhvera Oct 15, 2024
0210346
bring in CI changes
xiazhvera Oct 15, 2024
a751d76
Merge branch 'main' into grand_dispatch_queue
xiazhvera Oct 16, 2024
b44c510
update comments
xiazhvera Oct 25, 2024
b0f85f2
remove is_executing check
xiazhvera Oct 25, 2024
7bc39ee
improve comments
xiazhvera Oct 25, 2024
475c1f2
make all private function static
xiazhvera Oct 25, 2024
cf592a7
init variables
xiazhvera Oct 25, 2024
1803c0f
clang-format
xiazhvera Oct 25, 2024
977c4f7
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 7, 2024
eab14fa
fix header update
xiazhvera Nov 7, 2024
55de953
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 8, 2024
74019cf
update ci flags
xiazhvera Nov 8, 2024
5d22a69
update setup switch default event loop
xiazhvera Nov 8, 2024
600421e
revert function rename
xiazhvera Nov 8, 2024
f808b35
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 8, 2024
4a8007a
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 9, 2024
70008b1
fix implicit function call
xiazhvera Nov 9, 2024
8bd9808
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 9, 2024
8d946db
temporary remove dispatch queue wrap
xiazhvera Nov 9, 2024
1212977
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 9, 2024
afd634d
update dispatch queue related flags
xiazhvera Nov 9, 2024
6b92e59
hide dispatch queue header
xiazhvera Nov 11, 2024
94f95c1
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 12, 2024
22c6363
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 12, 2024
c507d13
update comments
xiazhvera Nov 12, 2024
c54b99e
rename enum
xiazhvera Nov 12, 2024
69cbb09
lint
xiazhvera Nov 12, 2024
5fc5270
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 12, 2024
7d20796
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 12, 2024
691aa17
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 25, 2024
2461b43
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 25, 2024
6783915
Grand dispatch queue context (#697)
xiazhvera Nov 29, 2024
85bf6ce
move aws_io_handle
xiazhvera Dec 3, 2024
ef012d3
schedule service entry on dispatch queue resume
xiazhvera Dec 3, 2024
8bb613e
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Dec 4, 2024
7cdd319
WIP code review update
xiazhvera Dec 5, 2024
d45eb98
wip update cr
xiazhvera Dec 10, 2024
cfa0399
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Dec 18, 2024
f4414aa
refactor dispatch queue release process/update iteartion schedule pro…
xiazhvera Dec 18, 2024
e1ce086
set up impl_data of event loop ealier
xiazhvera Dec 18, 2024
a93216b
revert ci change
xiazhvera Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,15 @@ jobs:

macos:
runs-on: macos-14 # latest
strategy:
matrix:
eventloop: ["-DAWS_USE_DISPATCH_QUEUE=ON", "-DAWS_USE_DISPATCH_QUEUE=OFF"]
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }}
./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=${{ matrix.eventloop }}

macos-x64:
runs-on: macos-14-large # latest
Expand All @@ -176,12 +179,15 @@ jobs:

macos-debug:
runs-on: macos-14 # latest
strategy:
matrix:
eventloop: ["-DAWS_USE_DISPATCH_QUEUE=ON", "-DAWS_USE_DISPATCH_QUEUE=OFF"]
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }} --config Debug
./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=${{ matrix.eventloop }} --config Debug

freebsd:
runs-on: ubuntu-22.04 # latest
Expand Down
31 changes: 23 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ file(GLOB AWS_IO_TESTING_HEADERS
"include/aws/testing/*.h"
)


file(GLOB AWS_IO_PRIV_HEADERS
"include/aws/io/private/*.h"
)
Expand Down Expand Up @@ -79,7 +78,7 @@ if (WIN32)
)
list(APPEND AWS_IO_OS_SRC ${AWS_IO_IOCP_SRC})

set(EVENT_LOOP_DEFINE "IO_COMPLETION_PORTS")
set(EVENT_LOOP_DEFINES "AWS_USE_IO_COMPLETION_PORTS")
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
endif ()

if (MSVC)
Expand All @@ -106,7 +105,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Androi
)
set(PLATFORM_LIBS "")

set(EVENT_LOOP_DEFINE "EPOLL")
set(EVENT_LOOP_DEFINES "-DAWS_USE_EPOLL")
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
set(USE_S2N ON)

elseif (APPLE)
Expand All @@ -117,17 +116,33 @@ 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)
if (NOT SECURITY_LIB)
message(FATAL_ERROR "Security framework not found")
endif ()

find_library(NETWORK_LIB Network)
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
if (NOT NETWORK_LIB)
message(FATAL_ERROR "Network framework not found")
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
endif ()

#No choice on TLS for apple, darwinssl will always be used.
list(APPEND PLATFORM_LIBS "-framework Security")
set(EVENT_LOOP_DEFINE "KQUEUE")
list(APPEND PLATFORM_LIBS "-framework Security -framework Network")
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved

if(AWS_USE_DISPATCH_QUEUE OR IOS)
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
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 All @@ -138,7 +153,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetB
"source/posix/*.c"
)

set(EVENT_LOOP_DEFINE "KQUEUE")
set(EVENT_LOOP_DEFINES "-DAWS_USE_KQUEUE")
set(USE_S2N ON)

endif()
Expand Down Expand Up @@ -191,7 +206,7 @@ aws_add_sanitizers(${PROJECT_NAME})
# We are not ABI stable yet
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION 1.0.0)

target_compile_definitions(${PROJECT_NAME} PUBLIC "-DAWS_USE_${EVENT_LOOP_DEFINE}")
target_compile_definitions(${PROJECT_NAME} PUBLIC "${EVENT_LOOP_DEFINES}")
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved

if (BYO_CRYPTO)
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DBYO_CRYPTO")
Expand Down
99 changes: 78 additions & 21 deletions include/aws/io/event_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ 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 {
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
AWS_EVENT_LOOP_STYLE_UNDEFINED = 0,
AWS_EVENT_LOOP_STYLE_POLL_BASED = 1,
AWS_EVENT_LOOP_STYLE_COMPLETION_PORT_BASED = 2,
};

struct aws_event_loop_vtable {
void (*destroy)(struct aws_event_loop *event_loop);
Expand All @@ -88,16 +92,16 @@ struct aws_event_loop_vtable {
void (*schedule_task_now)(struct aws_event_loop *event_loop, struct aws_task *task);
void (*schedule_task_future)(struct aws_event_loop *event_loop, struct aws_task *task, uint64_t run_at_nanos);
void (*cancel_task)(struct aws_event_loop *event_loop, struct aws_task *task);
#if AWS_USE_IO_COMPLETION_PORTS
int (*connect_to_io_completion_port)(struct aws_event_loop *event_loop, struct aws_io_handle *handle);
#else
int (*subscribe_to_io_events)(
struct aws_event_loop *event_loop,
struct aws_io_handle *handle,
int events,
aws_event_loop_on_event_fn *on_event,
void *user_data);
#endif
union {
int (*connect_to_completion_port)(struct aws_event_loop *event_loop, struct aws_io_handle *handle);
int (*subscribe_to_io_events)(
struct aws_event_loop *event_loop,
struct aws_io_handle *handle,
int events,
aws_event_loop_on_event_fn *on_event,
void *user_data);
} register_style;
enum aws_event_loop_style event_loop_style;
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
int (*unsubscribe_from_io_events)(struct aws_event_loop *event_loop, struct aws_io_handle *handle);
void (*free_io_event_resources)(void *user_data);
bool (*is_on_callers_thread)(struct aws_event_loop *event_loop);
Expand Down Expand Up @@ -140,6 +144,21 @@ struct aws_event_loop_group {
struct aws_shutdown_callback_options shutdown_options;
};

typedef struct aws_event_loop *(aws_new_system_event_loop_fn)(struct aws_allocator *alloc,
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
const struct aws_event_loop_options *options);

struct aws_event_loop_configuration {
enum aws_event_loop_style style;
aws_new_system_event_loop_fn *event_loop_new_fn;
const char *name;
bool is_default;
};
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved

struct aws_event_loop_configuration_group {
size_t configuration_count;
const struct aws_event_loop_configuration *configurations;
};

AWS_EXTERN_C_BEGIN

#ifdef AWS_USE_IO_COMPLETION_PORTS
Expand All @@ -166,6 +185,10 @@ AWS_IO_API
struct _OVERLAPPED *aws_overlapped_to_windows_overlapped(struct aws_overlapped *overlapped);
#endif /* AWS_USE_IO_COMPLETION_PORTS */

/* Get available event-loop configurations, this will return each available event-loop implementation for the current
* running system */
AWS_IO_API const struct aws_event_loop_configuration_group *aws_event_loop_get_available_configurations(void);
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates an instance of the default event loop implementation for the current architecture and operating system.
*/
Expand All @@ -181,6 +204,38 @@ struct aws_event_loop *aws_event_loop_new_default_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options);

// DEBUG WIP We should expose or condense all these def specific function APIs and not make them
// defined specific. Consolidation of them should work and branched logic within due to all the
// arguments being the same. Let's move away from different API based on framework and instead
// raise an unsupported platform error or simply use branching in implementation.
#ifdef AWS_USE_IO_COMPLETION_PORTS
AWS_IO_API
struct aws_event_loop *aws_event_loop_new_iocp_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options);
#endif /* AWS_USE_IO_COMPLETION_PORTS */

#ifdef AWS_USE_DISPATCH_QUEUE
AWS_IO_API
struct aws_event_loop *aws_event_loop_new_dispatch_queue_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options);
#endif /* AWS_USE_DISPATCH_QUEUE */

#ifdef AWS_USE_KQUEUE
AWS_IO_API
struct aws_event_loop *aws_event_loop_new_kqueue_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options);
#endif /* AWS_USE_KQUEUE */

#ifdef AWS_USE_EPOLL
AWS_IO_API
struct aws_event_loop *aws_event_loop_new_epoll_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options);
#endif /* AWS_USE_EPOLL */

/**
* Invokes the destroy() fn for the event loop implementation.
* If the event loop is still in a running state, this function will block waiting on the event loop to shutdown.
Expand Down Expand Up @@ -319,8 +374,6 @@ void aws_event_loop_schedule_task_future(
AWS_IO_API
void aws_event_loop_cancel_task(struct aws_event_loop *event_loop, struct aws_task *task);

#if AWS_USE_IO_COMPLETION_PORTS

/**
* Associates an aws_io_handle with the event loop's I/O Completion Port.
*
Expand All @@ -332,11 +385,7 @@ void aws_event_loop_cancel_task(struct aws_event_loop *event_loop, struct aws_ta
* A handle may only be connected to one event loop in its lifetime.
*/
AWS_IO_API
int aws_event_loop_connect_handle_to_io_completion_port(
struct aws_event_loop *event_loop,
struct aws_io_handle *handle);

#else /* !AWS_USE_IO_COMPLETION_PORTS */
int aws_event_loop_connect_handle_to_completion_port(struct aws_event_loop *event_loop, struct aws_io_handle *handle);

/**
* Subscribes on_event to events on the event-loop for handle. events is a bitwise concatenation of the events that were
Expand All @@ -353,8 +402,6 @@ int aws_event_loop_subscribe_to_io_events(
aws_event_loop_on_event_fn *on_event,
void *user_data);

#endif /* AWS_USE_IO_COMPLETION_PORTS */

/**
* Unsubscribes handle from event-loop notifications.
* This function is not thread safe and should be called inside the event-loop's thread.
Expand Down Expand Up @@ -399,6 +446,13 @@ struct aws_event_loop_group *aws_event_loop_group_new(
void *new_loop_user_data,
const struct aws_shutdown_callback_options *shutdown_options);

AWS_IO_API
struct aws_event_loop_group *aws_event_loop_group_new_from_config(
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
struct aws_allocator *allocator,
const struct aws_event_loop_configuration *config,
uint16_t max_threads,
const struct aws_shutdown_callback_options *shutdown_options);

/** Creates an event loop group, with clock, number of loops to manage, the function to call for creating a new
* event loop, and also pins all loops to hw threads on the same cpu_group (e.g. NUMA nodes). Note:
* If el_count exceeds the number of hw threads in the cpu_group it will be ignored on the assumption that if you
Expand Down Expand Up @@ -456,6 +510,9 @@ struct aws_event_loop_group *aws_event_loop_group_acquire(struct aws_event_loop_
AWS_IO_API
void aws_event_loop_group_release(struct aws_event_loop_group *el_group);

AWS_IO_API
enum aws_event_loop_style aws_event_loop_group_get_style(struct aws_event_loop_group *el_group);
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved

AWS_IO_API
struct aws_event_loop *aws_event_loop_group_get_loop_at(struct aws_event_loop_group *el_group, size_t index);

Expand Down
12 changes: 12 additions & 0 deletions include/aws/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ AWS_PUSH_SANE_WARNING_LEVEL

#define AWS_C_IO_PACKAGE_ID 1

struct aws_io_handle;
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved

#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 */

struct aws_io_handle {
union {
int fd;
/* on Apple systems, handle is of type nw_connection_t. On Windows, it's a SOCKET handle. */
void *handle;
} data;
void *additional_data;
#ifdef AWS_USE_DISPATCH_QUEUE
aws_io_set_queue_on_handle_fn *set_queue;
aws_io_clear_queue_on_handle_fn *clear_queue;
#endif /* AWS_USE_DISPATCH_QUEUE */
};

enum aws_io_message_type {
Expand Down
63 changes: 63 additions & 0 deletions include/aws/io/private/dispatch_queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef AWS_IO_PRIVATE_DISPATCH_QUEUE_H
#define AWS_IO_PRIVATE_DISPATCH_QUEUE_H
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#include <Security/Security.h>
#include <aws/common/mutex.h>
#include <aws/common/thread.h>
#include <aws/io/tls_channel_handler.h>
#include <dispatch/dispatch.h>

struct secure_transport_ctx {
struct aws_tls_ctx ctx;
CFAllocatorRef wrapped_allocator;
CFArrayRef certs;
SecIdentityRef secitem_identity;
CFArrayRef ca_cert;
enum aws_tls_versions minimum_version;
struct aws_string *alpn_list;
bool verify_peer;
};

struct dispatch_scheduling_state {
// Let's us skip processing an iteration task if one is already in the middle
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
// of executing
bool is_executing_iteration;

// List<scheduled_service_entry> in sorted order by timestamp
//
// When we go to schedule a new iteration, we check here first to see
// if our scheduling attempt is redundant
struct aws_linked_list scheduled_services;
};

struct dispatch_loop {
struct aws_allocator *allocator;
struct aws_ref_count ref_count;
dispatch_queue_t dispatch_queue;
struct aws_task_scheduler scheduler;
struct aws_linked_list local_cross_thread_tasks;

// Apple dispatch queue uses the id string to identify the dispatch queue
struct aws_string *dispatch_queue_id;

struct {
struct dispatch_scheduling_state scheduling_state;
struct aws_linked_list cross_thread_tasks;
struct aws_mutex lock;
bool suspended;
// `is_executing` flag and `current_thread_id` together are used to identify the excuting
// thread id for dispatch queue. See `static bool s_is_on_callers_thread(struct aws_event_loop *event_loop)`
// for details.
bool is_executing;
aws_thread_id_t current_thread_id;
} synced_data;

bool wakeup_schedule_needed;
bool is_destroying;
};

#endif /* #ifndef AWS_IO_PRIVATE_DISPATCH_QUEUE_H */
5 changes: 3 additions & 2 deletions source/bsd/kqueue_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ struct aws_event_loop_vtable s_kqueue_vtable = {
.wait_for_stop_completion = s_wait_for_stop_completion,
.schedule_task_now = s_schedule_task_now,
.schedule_task_future = s_schedule_task_future,
.subscribe_to_io_events = s_subscribe_to_io_events,
.register_style.subscribe_to_io_events = s_subscribe_to_io_events,
.event_loop_style = AWS_EVENT_LOOP_STYLE_POLL_BASED,
.cancel_task = s_cancel_task,
.unsubscribe_from_io_events = s_unsubscribe_from_io_events,
.free_io_event_resources = s_free_io_event_resources,
.is_on_callers_thread = s_is_event_thread,
};

struct aws_event_loop *aws_event_loop_new_default_with_options(
struct aws_event_loop *aws_event_loop_new_kqueue_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options) {
AWS_ASSERT(alloc);
Expand Down
Loading
Loading