Skip to content

Commit

Permalink
Branched nw_socket work (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbSteveK authored Sep 24, 2024
1 parent 429bf26 commit 2282f8f
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 149 deletions.
52 changes: 52 additions & 0 deletions include/aws/io/private/dispatch_queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#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 <dispatch/dispatch.h>
#include <Security/Security.h>
#include <aws/io/tls_channel_handler.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
// 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;

struct {
struct dispatch_scheduling_state scheduling_state;
struct aws_linked_list cross_thread_tasks;
struct aws_mutex lock;
bool suspended;
} synced_data;

bool wakeup_schedule_needed;
};

#endif /* #ifndef AWS_IO_PRIVATE_DISPATCH_QUEUE_H */
30 changes: 1 addition & 29 deletions source/darwin/dispatch_queue_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Block.h>
#include <dispatch/dispatch.h>
#include <dispatch/queue.h>
#include <aws/io/private/dispatch_queue.h>

static void s_destroy(struct aws_event_loop *event_loop);
static int s_run(struct aws_event_loop *event_loop);
Expand Down Expand Up @@ -46,42 +47,13 @@ static struct aws_event_loop_vtable s_vtable = {
.is_on_callers_thread = s_is_on_callers_thread,
};

struct dispatch_scheduling_state {
// Let's us skip processing an iteration task if one is already in the middle
// 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 scheduled_service_entry {
struct aws_allocator *allocator;
uint64_t timestamp;
struct aws_linked_list_node node;
struct aws_event_loop *loop; // might eventually need to be ref-counted for cleanup?
};

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;

struct {
struct dispatch_scheduling_state scheduling_state;
struct aws_linked_list cross_thread_tasks;
struct aws_mutex lock;
bool suspended;
} synced_data;

bool wakeup_schedule_needed;
};

struct scheduled_service_entry *scheduled_service_entry_new(struct aws_event_loop *loop, uint64_t timestamp) {
struct scheduled_service_entry *entry = aws_mem_calloc(loop->alloc, 1, sizeof(struct scheduled_service_entry));

Expand Down
Loading

0 comments on commit 2282f8f

Please sign in to comment.