aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/aws-c-io/source/linux/epoll_event_loop.c
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.ru>2022-05-11 12:12:06 +0300
committerthegeorg <thegeorg@yandex-team.ru>2022-05-11 12:12:06 +0300
commit62f93da087b2fec0f89979fd11ac4d754ca36253 (patch)
tree67bf8ceb55e2d079f3575f9a7373584ad407d2a5 /contrib/restricted/aws/aws-c-io/source/linux/epoll_event_loop.c
parent8d55620139d4309265409767f873ba83fe046418 (diff)
downloadydb-62f93da087b2fec0f89979fd11ac4d754ca36253.tar.gz
Update aws-c-common and aws-c-io
* Update `contrib/restricted/aws/aws-c-io` to 0.11.0 * Backport cJSON symbol renaming logic from aws-sdk-cpp upstream ref:396829235a01ed34888651ee38ebd76c95510d6b
Diffstat (limited to 'contrib/restricted/aws/aws-c-io/source/linux/epoll_event_loop.c')
-rw-r--r--contrib/restricted/aws/aws-c-io/source/linux/epoll_event_loop.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/contrib/restricted/aws/aws-c-io/source/linux/epoll_event_loop.c b/contrib/restricted/aws/aws-c-io/source/linux/epoll_event_loop.c
index 8957e6c2b6..c7ad9251a3 100644
--- a/contrib/restricted/aws/aws-c-io/source/linux/epoll_event_loop.c
+++ b/contrib/restricted/aws/aws-c-io/source/linux/epoll_event_loop.c
@@ -79,6 +79,7 @@ static struct aws_event_loop_vtable s_vtable = {
struct epoll_loop {
struct aws_task_scheduler scheduler;
struct aws_thread thread_created_on;
+ struct aws_thread_options thread_options;
aws_thread_id_t thread_joined_to;
struct aws_atomic_var running_thread_id;
struct aws_io_handle read_task_handle;
@@ -110,14 +111,19 @@ enum {
int aws_open_nonblocking_posix_pipe(int pipe_fds[2]);
/* Setup edge triggered epoll with a scheduler. */
-struct aws_event_loop *aws_event_loop_new_default(struct aws_allocator *alloc, aws_io_clock_fn *clock) {
+struct aws_event_loop *aws_event_loop_new_default_with_options(
+ struct aws_allocator *alloc,
+ const struct aws_event_loop_options *options) {
+ AWS_PRECONDITION(options);
+ AWS_PRECONDITION(options->clock);
+
struct aws_event_loop *loop = aws_mem_calloc(alloc, 1, sizeof(struct aws_event_loop));
if (!loop) {
return NULL;
}
AWS_LOGF_INFO(AWS_LS_IO_EVENT_LOOP, "id=%p: Initializing edge-triggered epoll", (void *)loop);
- if (aws_event_loop_init_base(loop, alloc, clock)) {
+ if (aws_event_loop_init_base(loop, alloc, options->clock)) {
goto clean_up_loop;
}
@@ -126,6 +132,12 @@ struct aws_event_loop *aws_event_loop_new_default(struct aws_allocator *alloc, a
goto cleanup_base_loop;
}
+ if (options->thread_options) {
+ epoll_loop->thread_options = *options->thread_options;
+ } else {
+ epoll_loop->thread_options = *aws_default_thread_options();
+ }
+
/* initialize thread id to NULL, it should be updated when the event loop thread starts. */
aws_atomic_init_ptr(&epoll_loop->running_thread_id, NULL);
@@ -259,7 +271,9 @@ static int s_run(struct aws_event_loop *event_loop) {
AWS_LOGF_INFO(AWS_LS_IO_EVENT_LOOP, "id=%p: Starting event-loop thread.", (void *)event_loop);
epoll_loop->should_continue = true;
- if (aws_thread_launch(&epoll_loop->thread_created_on, &s_main_loop, event_loop, NULL)) {
+ aws_thread_increment_unjoined_count();
+ if (aws_thread_launch(&epoll_loop->thread_created_on, &s_main_loop, event_loop, &epoll_loop->thread_options)) {
+ aws_thread_decrement_unjoined_count();
AWS_LOGF_FATAL(AWS_LS_IO_EVENT_LOOP, "id=%p: thread creation failed.", (void *)event_loop);
epoll_loop->should_continue = false;
return AWS_OP_ERR;
@@ -303,7 +317,9 @@ static int s_stop(struct aws_event_loop *event_loop) {
static int s_wait_for_stop_completion(struct aws_event_loop *event_loop) {
struct epoll_loop *epoll_loop = event_loop->impl_data;
- return aws_thread_join(&epoll_loop->thread_created_on);
+ int result = aws_thread_join(&epoll_loop->thread_created_on);
+ aws_thread_decrement_unjoined_count();
+ return result;
}
static void s_schedule_task_common(struct aws_event_loop *event_loop, struct aws_task *task, uint64_t run_at_nanos) {
@@ -568,8 +584,10 @@ static void s_main_loop(void *args) {
* process queued subscription cleanups.
*/
while (epoll_loop->should_continue) {
+
AWS_LOGF_TRACE(AWS_LS_IO_EVENT_LOOP, "id=%p: waiting for a maximum of %d ms", (void *)event_loop, timeout);
int event_count = epoll_wait(epoll_loop->epoll_fd, events, MAX_EVENTS, timeout);
+ aws_event_loop_register_tick_start(event_loop);
AWS_LOGF_TRACE(
AWS_LS_IO_EVENT_LOOP, "id=%p: wake up with %d events to process.", (void *)event_loop, event_count);
@@ -646,6 +664,8 @@ static void s_main_loop(void *args) {
(unsigned long long)timeout_ns,
timeout);
}
+
+ aws_event_loop_register_tick_end(event_loop);
}
AWS_LOGF_DEBUG(AWS_LS_IO_EVENT_LOOP, "id=%p: exiting main loop", (void *)event_loop);