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 68 commits into
base: runtime_select_event_loop
Choose a base branch
from

Conversation

sbSteveK
Copy link
Contributor

@sbSteveK sbSteveK commented Jul 29, 2024

Integration of Apple's grand dispatch queue with event loop

The CI is failing for dispatch queue because of the apple network socket is not in. The socket related changes is in PR: #662

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 63.15789% with 7 lines in your changes missing coverage. Please review.

Project coverage is 79.65%. Comparing base (53fc1fc) to head (2461b43).

Files with missing lines Patch % Lines
source/event_loop.c 63.15% 7 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                      @@
##           runtime_select_event_loop     #661      +/-   ##
=============================================================
- Coverage                      79.66%   79.65%   -0.01%     
=============================================================
  Files                             30       30              
  Lines                           6122     6124       +2     
=============================================================
+ Hits                            4877     4878       +1     
- Misses                          1245     1246       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
include/aws/io/event_loop.h Outdated Show resolved Hide resolved
include/aws/io/event_loop.h Outdated Show resolved Hide resolved
include/aws/io/event_loop.h Outdated Show resolved Hide resolved
include/aws/io/event_loop.h Outdated Show resolved Hide resolved
include/aws/io/event_loop.h Outdated Show resolved Hide resolved
@xiazhvera xiazhvera changed the base branch from main to runtime_select_event_loop November 8, 2024 19:22
include/aws/io/event_loop.h Outdated Show resolved Hide resolved
@@ -14,12 +14,20 @@ AWS_PUSH_SANE_WARNING_LEVEL

#define AWS_C_IO_PACKAGE_ID 1

struct aws_io_handle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aws_io_handle should be moved to a private header. I don't see any references outside aws-c-io

@@ -0,0 +1,66 @@
#ifndef AWS_IO_PRIVATE_DISPATCH_QUEUE_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this header necessary?

Does everything in it need to be visible?

I would make the guard symbol AWS_IO_DARWIN_DISPATCH_QUEUE_H if it stays

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data structures here will be required for SecItem related changes, so we shared them in the private header here.

source/socket.c Outdated
@@ -156,6 +156,11 @@ void aws_socket_endpoint_init_local_address_for_test(struct aws_socket_endpoint
struct aws_byte_buf uuid_buf = aws_byte_buf_from_empty_array(uuid_str, sizeof(uuid_str));
AWS_FATAL_ASSERT(aws_uuid_to_str(&uuid, &uuid_buf) == AWS_OP_SUCCESS);

#if defined(WS_USE_APPLE_NETWORK_FRAMEWORK)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these be elif with a fatal assert for fall through?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think this should be "AWS_USE_APPLE_NETWORK_FRAMEWORK"

entry->timestamp = timestamp;
entry->loop = loop;
struct dispatch_loop *dispatch_loop = loop->impl_data;
aws_ref_count_acquire(&dispatch_loop->ref_count);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concern: if scheduling service implies an inc-ref does that mean that an event loop won't terminate until all service schedules run? That would be bad.

if (dispatch_loop->synced_data.suspended) {
AWS_LOGF_INFO(AWS_LS_IO_EVENT_LOOP, "id=%p: Starting event-loop thread.", (void *)event_loop);
dispatch_resume(dispatch_loop->dispatch_queue);
dispatch_loop->synced_data.suspended = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this schedule a service on the off-chance that there were scheduled tasks at the time of suspension?

aws_mutex_lock(&dispatch_loop->synced_data.lock);
bool should_schedule = false;

bool is_empty = aws_linked_list_empty(&dispatch_loop->synced_data.cross_thread_tasks);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like was_empty would be slightly better

struct aws_event_loop *event_loop = entry->loop;
struct dispatch_loop *dispatch_loop = event_loop->impl_data;
AWS_ASSERT(event_loop && dispatch_loop);
if (entry->cancel) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't safe. You set the cancel flag under the event loop lock but you don't check it under the lock. Check should be moved inside begin_iteration

}

aws_mutex_lock(&dispatch_loop->synced_data.lock);
dispatch_loop->synced_data.current_thread_id = aws_thread_current_thread_id();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't this be set in begin_iteration?

aws_event_loop_register_tick_end(event_loop);

aws_mutex_lock(&dispatch_loop->synced_data.lock);
dispatch_loop->synced_data.is_executing = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make a part of end_iteration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants