Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Bret Ambrose committed Feb 10, 2025
1 parent f19f734 commit 07c46bd
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 17 deletions.
16 changes: 15 additions & 1 deletion include/aws/io/event_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ typedef void(aws_event_loop_on_event_fn)(
* @internal
*/
struct aws_event_loop_vtable {
void (*destroy)(struct aws_event_loop *event_loop);
void (*start_destroy)(struct aws_event_loop *event_loop);
void (*complete_destroy)(struct aws_event_loop *event_loop);
int (*run)(struct aws_event_loop *event_loop);
int (*stop)(struct aws_event_loop *event_loop);
int (*wait_for_stop_completion)(struct aws_event_loop *event_loop);
Expand Down Expand Up @@ -255,6 +256,19 @@ void aws_event_loop_clean_up_base(struct aws_event_loop *event_loop);
AWS_IO_API
void aws_event_loop_destroy(struct aws_event_loop *event_loop);

/**
* @internal
*/
AWS_IO_API
void aws_event_loop_start_destroy(struct aws_event_loop *event_loop);

/**
* @internal
*
*/
AWS_IO_API
void aws_event_loop_complete_destroy(struct aws_event_loop *event_loop);

AWS_EXTERN_C_END

AWS_POP_SANE_WARNING_LEVEL
Expand Down
9 changes: 7 additions & 2 deletions include/aws/testing/io_testing_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ static bool s_testing_loop_is_on_callers_thread(struct aws_event_loop *event_loo
return testing_loop->mock_on_callers_thread;
}

static void s_testing_loop_destroy(struct aws_event_loop *event_loop) {
static void s_testing_loop_start_destroy(struct aws_event_loop *event_loop) {
(void)event_loop;
}

static void s_testing_loop_complete_destroy(struct aws_event_loop *event_loop) {
struct testing_loop *testing_loop = (struct testing_loop *)aws_event_loop_get_impl(event_loop);
struct aws_allocator *allocator = testing_loop->allocator;
aws_task_scheduler_clean_up(&testing_loop->scheduler);
Expand All @@ -67,7 +71,8 @@ static void s_testing_loop_destroy(struct aws_event_loop *event_loop) {
}

static struct aws_event_loop_vtable s_testing_loop_vtable = {
.destroy = s_testing_loop_destroy,
.start_destroy = s_testing_loop_start_destroy,
.complete_destroy = s_testing_loop_complete_destroy,
.is_on_callers_thread = s_testing_loop_is_on_callers_thread,
.run = s_testing_loop_run,
.schedule_task_now = s_testing_loop_schedule_task_now,
Expand Down
12 changes: 9 additions & 3 deletions source/bsd/kqueue_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#include <limits.h>
#include <unistd.h>

static void s_destroy(struct aws_event_loop *event_loop);
static void s_start_destroy(struct aws_event_loop *event_loop);
static void s_complete_destroy(struct aws_event_loop *event_loop);
static int s_run(struct aws_event_loop *event_loop);
static int s_stop(struct aws_event_loop *event_loop);
static int s_wait_for_stop_completion(struct aws_event_loop *event_loop);
Expand Down Expand Up @@ -135,7 +136,8 @@ enum {
};

struct aws_event_loop_vtable s_kqueue_vtable = {
.destroy = s_destroy,
.start_destroy = s_start_destroy,
.complete_destroy = s_complete_destroy,
.run = s_run,
.stop = s_stop,
.wait_for_stop_completion = s_wait_for_stop_completion,
Expand Down Expand Up @@ -313,7 +315,11 @@ struct aws_event_loop *aws_event_loop_new_with_kqueue(
}
#endif // AWS_ENABLE_KQUEUE

static void s_destroy(struct aws_event_loop *event_loop) {
static void s_start_destroy(struct aws_event_loop *event_loop) {
(void)event_loop;
}

static void s_complete_destroy(struct aws_event_loop *event_loop) {
AWS_LOGF_INFO(AWS_LS_IO_EVENT_LOOP, "id=%p: destroying event_loop", (void *)event_loop);
struct kqueue_loop *impl = event_loop->impl_data;

Expand Down
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 @@ -19,7 +19,8 @@
#include <dispatch/dispatch.h>
#include <dispatch/queue.h>

static void s_destroy(struct aws_event_loop *event_loop);
static void s_start_destroy(struct aws_event_loop *event_loop);
static void s_complete_destroy(struct aws_event_loop *event_loop);
static int s_run(struct aws_event_loop *event_loop);
static int s_stop(struct aws_event_loop *event_loop);
static int s_wait_for_stop_completion(struct aws_event_loop *event_loop);
Expand Down Expand Up @@ -60,7 +61,8 @@ static void *s_get_base_event_loop_group(struct aws_event_loop *event_loop);
static bool s_is_on_callers_thread(struct aws_event_loop *event_loop);

static struct aws_event_loop_vtable s_vtable = {
.destroy = s_destroy,
.start_destroy = s_start_destroy,
.complete_destroy = s_complete_destroy,
.run = s_run,
.stop = s_stop,
.wait_for_stop_completion = s_wait_for_stop_completion,
Expand Down Expand Up @@ -380,7 +382,11 @@ static void s_dispatch_queue_destroy_task(void *context) {
s_dispatch_event_loop_destroy(dispatch_loop->base_loop);
}

static void s_destroy(struct aws_event_loop *event_loop) {
static void s_start_destroy(struct aws_event_loop *event_loop) {
(void)event_loop;
}

static void s_complete_destroy(struct aws_event_loop *event_loop) {
AWS_LOGF_TRACE(AWS_LS_IO_EVENT_LOOP, "id=%p: Destroying Dispatch Queue Event Loop", (void *)event_loop);
struct aws_dispatch_loop *dispatch_loop = event_loop->impl_data;

Expand Down
11 changes: 11 additions & 0 deletions source/darwin/dispatch_queue_event_loop_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@
#include <aws/io/tls_channel_handler.h>
#include <dispatch/dispatch.h>

enum aws_dispatch_loop_execution_state {
AWS_DLES_SUSPENDED,
AWS_DLES_RUNNING,
AWS_DLES_SHUTTING_DOWN,
AWS_DLES_TERMINATED
};

struct aws_dispatch_loop {
struct aws_allocator *allocator;
dispatch_queue_t dispatch_queue;
struct aws_task_scheduler scheduler;
struct aws_event_loop *base_loop;
struct aws_event_loop_group *base_elg;

//struct aws_ref_count ref_count;

/* Synced data handle cross thread tasks and events, and event loop operations*/
struct {
/*
Expand All @@ -43,6 +52,7 @@ struct aws_dispatch_loop {
* Calling dispatch_sync() on a suspended dispatch queue will deadlock.
*/
bool suspended;
//enum aws_dispatch_loop_execution_state execution_state;

struct aws_linked_list cross_thread_tasks;

Expand All @@ -54,6 +64,7 @@ struct aws_dispatch_loop {
* redundant.
*/
struct aws_priority_queue scheduled_iterations;
//struct aws_linked_list scheduled_iterations;
} synced_data;
};

Expand Down
28 changes: 26 additions & 2 deletions source/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,34 @@ void aws_event_loop_destroy(struct aws_event_loop *event_loop) {
return;
}

AWS_ASSERT(event_loop->vtable && event_loop->vtable->destroy);
AWS_ASSERT(event_loop->vtable && event_loop->vtable->start_destroy);
AWS_ASSERT(event_loop->vtable && event_loop->vtable->complete_destroy);
AWS_ASSERT(!aws_event_loop_thread_is_callers_thread(event_loop));

event_loop->vtable->destroy(event_loop);
event_loop->vtable->start_destroy(event_loop);
event_loop->vtable->complete_destroy(event_loop);
}

void aws_event_loop_start_destroy(struct aws_event_loop *event_loop) {
if (!event_loop) {
return;
}

AWS_ASSERT(event_loop->vtable && event_loop->vtable->start_destroy);
AWS_ASSERT(!aws_event_loop_thread_is_callers_thread(event_loop));

event_loop->vtable->start_destroy(event_loop);
}

void aws_event_loop_complete_destroy(struct aws_event_loop *event_loop) {
if (!event_loop) {
return;
}

AWS_ASSERT(event_loop->vtable && event_loop->vtable->complete_destroy);
AWS_ASSERT(!aws_event_loop_thread_is_callers_thread(event_loop));

event_loop->vtable->complete_destroy(event_loop);
}

int aws_event_loop_fetch_local_object(
Expand Down
12 changes: 9 additions & 3 deletions source/linux/epoll_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
# define EPOLLRDHUP 0x2000
#endif

static void s_destroy(struct aws_event_loop *event_loop);
static void s_start_destroy(struct aws_event_loop *event_loop);
static void s_complete_destroy(struct aws_event_loop *event_loop);
static int s_run(struct aws_event_loop *event_loop);
static int s_stop(struct aws_event_loop *event_loop);
static int s_wait_for_stop_completion(struct aws_event_loop *event_loop);
Expand Down Expand Up @@ -81,7 +82,8 @@ static bool s_is_on_callers_thread(struct aws_event_loop *event_loop);
static void aws_event_loop_thread(void *args);

static struct aws_event_loop_vtable s_vtable = {
.destroy = s_destroy,
.start_destroy = s_start_destroy,
.complete_destroy = s_complete_destroy,
.run = s_run,
.stop = s_stop,
.wait_for_stop_completion = s_wait_for_stop_completion,
Expand Down Expand Up @@ -248,7 +250,11 @@ struct aws_event_loop *aws_event_loop_new_with_epoll(
return NULL;
}

static void s_destroy(struct aws_event_loop *event_loop) {
static void s_start_destroy(struct aws_event_loop *event_loop) {
(void)event_loop;
}

static void s_complete_destroy(struct aws_event_loop *event_loop) {
AWS_LOGF_INFO(AWS_LS_IO_EVENT_LOOP, "id=%p: Destroying event_loop", (void *)event_loop);

struct epoll_loop *epoll_loop = event_loop->impl_data;
Expand Down
12 changes: 9 additions & 3 deletions source/windows/iocp/iocp_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ enum {
MAX_COMPLETION_PACKETS_PER_LOOP = 100,
};

static void s_destroy(struct aws_event_loop *event_loop);
static void s_start_destroy(struct aws_event_loop *event_loop);
static void s_complete_destroy(struct aws_event_loop *event_loop);
static int s_run(struct aws_event_loop *event_loop);
static int s_stop(struct aws_event_loop *event_loop);
static int s_wait_for_stop_completion(struct aws_event_loop *event_loop);
Expand Down Expand Up @@ -156,7 +157,8 @@ struct _OVERLAPPED *aws_overlapped_to_windows_overlapped(struct aws_overlapped *
}

struct aws_event_loop_vtable s_iocp_vtable = {
.destroy = s_destroy,
.start_destroy = s_start_destroy,
.complete_destroy = s_complete_destroy,
.run = s_run,
.stop = s_stop,
.wait_for_stop_completion = s_wait_for_stop_completion,
Expand Down Expand Up @@ -306,8 +308,12 @@ struct aws_event_loop *aws_event_loop_new_with_iocp(
return NULL;
}

static void s_start_destroy(struct aws_event_loop *event_loop) {
(void)event_loop;
}

/* Should not be called from event-thread */
static void s_destroy(struct aws_event_loop *event_loop) {
static void s_complete_destroy(struct aws_event_loop *event_loop) {
AWS_LOGF_TRACE(AWS_LS_IO_EVENT_LOOP, "id=%p: destroying event-loop", (void *)event_loop);

struct iocp_loop *impl = event_loop->impl_data;
Expand Down

0 comments on commit 07c46bd

Please sign in to comment.