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

Cleanup aws-lc thread locals in event loop threads #581

Merged
merged 7 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/proof-alarm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Check
run: |
TMPFILE=$(mktemp)
echo "8391c38acd85cca2a2892d02ebfd4ceb source/linux/epoll_event_loop.c" > $TMPFILE
echo "59be2f2fbbd5ff4a374589cfe408609f source/linux/epoll_event_loop.c" > $TMPFILE
md5sum --check $TMPFILE

# No further steps if successful
Expand Down
9 changes: 9 additions & 0 deletions source/bsd/kqueue_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <aws/io/logging.h>

#include <aws/cal/cal.h>
#include <aws/common/atomics.h>
#include <aws/common/clock.h>
#include <aws/common/mutex.h>
Expand Down Expand Up @@ -821,6 +822,12 @@ static int aws_event_loop_listen_for_io_events(int kq_fd, struct kevent kevents[
return kevent(kq_fd, NULL /*changelist*/, 0 /*nchanges*/, kevents /*eventlist*/, MAX_EVENTS /*nevents*/, timeout);
}

static void s_aws_kqueue_cleanup_aws_lc_thread_local_state(void *user_data) {
(void)user_data;

aws_cal_thread_clean_up();
}

static void aws_event_loop_thread(void *user_data) {
struct aws_event_loop *event_loop = user_data;
AWS_LOGF_INFO(AWS_LS_IO_EVENT_LOOP, "id=%p: main loop started", (void *)event_loop);
Expand Down Expand Up @@ -852,6 +859,8 @@ static void aws_event_loop_thread(void *user_data) {
DEFAULT_TIMEOUT_SEC,
MAX_EVENTS);

aws_thread_current_at_exit(s_aws_kqueue_cleanup_aws_lc_thread_local_state, NULL);

while (impl->thread_data.state == EVENT_THREAD_STATE_RUNNING) {
int num_io_handle_events = 0;
bool should_process_cross_thread_data = false;
Expand Down
9 changes: 9 additions & 0 deletions source/linux/epoll_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <aws/io/event_loop.h>

#include <aws/cal/cal.h>
#include <aws/common/atomics.h>
#include <aws/common/clock.h>
#include <aws/common/mutex.h>
Expand Down Expand Up @@ -562,6 +563,12 @@ static int aws_event_loop_listen_for_io_events(int epoll_fd, struct epoll_event
return epoll_wait(epoll_fd, events, MAX_EVENTS, timeout);
}

static void s_aws_epoll_cleanup_aws_lc_thread_local_state(void *user_data) {
(void)user_data;

aws_cal_thread_clean_up();
}

static void aws_event_loop_thread(void *args) {
struct aws_event_loop *event_loop = args;
AWS_LOGF_INFO(AWS_LS_IO_EVENT_LOOP, "id=%p: main loop started", (void *)event_loop);
Expand All @@ -576,6 +583,8 @@ static void aws_event_loop_thread(void *args) {
return;
}

aws_thread_current_at_exit(s_aws_epoll_cleanup_aws_lc_thread_local_state, NULL);

int timeout = DEFAULT_TIMEOUT;

struct epoll_event events[MAX_EVENTS];
Expand Down