From 8ada111f6d3ab40d1c33cf1a7b2546de9a47d1d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 17 May 2017 16:03:13 -0400 Subject: [PATCH 1/1] Fix: use lttng_waiter instead of futex in notification thread MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- .../lttng-sessiond/notification-thread-commands.c | 6 ++---- .../lttng-sessiond/notification-thread-commands.h | 5 +++-- src/bin/lttng-sessiond/notification-thread-events.c | 4 ++-- src/bin/lttng-sessiond/notification-thread.c | 12 +----------- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/bin/lttng-sessiond/notification-thread-commands.c b/src/bin/lttng-sessiond/notification-thread-commands.c index 5483a317f..d9fdf0158 100644 --- a/src/bin/lttng-sessiond/notification-thread-commands.c +++ b/src/bin/lttng-sessiond/notification-thread-commands.c @@ -20,7 +20,6 @@ #include "notification-thread.h" #include "notification-thread-commands.h" #include -#include #include #include #include @@ -30,6 +29,7 @@ void init_notification_thread_command(struct notification_thread_command *cmd) { memset(cmd, 0, sizeof(*cmd)); CDS_INIT_LIST_HEAD(&cmd->cmd_list_node); + lttng_waiter_init(&cmd->reply_waiter); } static @@ -39,8 +39,6 @@ int run_command_wait(struct notification_thread_handle *handle, int ret; uint64_t notification_counter = 1; - futex_nto1_prepare(&cmd->reply_futex); - pthread_mutex_lock(&handle->cmd_queue.lock); /* Add to queue. */ cds_list_add_tail(&cmd->cmd_list_node, @@ -59,7 +57,7 @@ int run_command_wait(struct notification_thread_handle *handle, } pthread_mutex_unlock(&handle->cmd_queue.lock); - futex_nto1_wait(&cmd->reply_futex); + lttng_waiter_wait(&cmd->reply_waiter); return 0; error_unlock_queue: pthread_mutex_unlock(&handle->cmd_queue.lock); diff --git a/src/bin/lttng-sessiond/notification-thread-commands.h b/src/bin/lttng-sessiond/notification-thread-commands.h index fc7e90bcb..8885d4faf 100644 --- a/src/bin/lttng-sessiond/notification-thread-commands.h +++ b/src/bin/lttng-sessiond/notification-thread-commands.h @@ -22,6 +22,7 @@ #include #include #include "notification-thread.h" +#include struct notification_thread_data; struct lttng_trigger; @@ -65,8 +66,8 @@ struct notification_thread_command { } remove_channel; } parameters; - /* Futex on which to wait for command reply (optional). */ - int32_t reply_futex; + /* lttng_waiter on which to wait for command reply (optional). */ + struct lttng_waiter reply_waiter; enum lttng_error_code reply_code; }; diff --git a/src/bin/lttng-sessiond/notification-thread-events.c b/src/bin/lttng-sessiond/notification-thread-events.c index 8e70baed5..b0657a4c5 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.c +++ b/src/bin/lttng-sessiond/notification-thread-events.c @@ -1110,12 +1110,12 @@ int handle_notification_thread_command( } end: cds_list_del(&cmd->cmd_list_node); - futex_nto1_wake(&cmd->reply_futex); + lttng_waiter_wake_up(&cmd->reply_waiter); pthread_mutex_unlock(&handle->cmd_queue.lock); return ret; error_unlock: /* Wake-up and return a fatal error to the calling thread. */ - futex_nto1_wake(&cmd->reply_futex); + lttng_waiter_wake_up(&cmd->reply_waiter); pthread_mutex_unlock(&handle->cmd_queue.lock); cmd->reply_code = LTTNG_ERR_FATAL; error: diff --git a/src/bin/lttng-sessiond/notification-thread.c b/src/bin/lttng-sessiond/notification-thread.c index 059e62059..e0937d8e5 100644 --- a/src/bin/lttng-sessiond/notification-thread.c +++ b/src/bin/lttng-sessiond/notification-thread.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -158,7 +157,6 @@ void notification_thread_handle_destroy( struct notification_thread_handle *handle) { int ret; - struct notification_thread_command *cmd, *tmp; if (!handle) { goto end; @@ -172,15 +170,7 @@ void notification_thread_handle_destroy( PERROR("close notification command queue event_fd"); } - pthread_mutex_lock(&handle->cmd_queue.lock); - /* Purge queue of in-flight commands and mark them as cancelled. */ - cds_list_for_each_entry_safe(cmd, tmp, &handle->cmd_queue.list, - cmd_list_node) { - cds_list_del(&cmd->cmd_list_node); - cmd->reply_code = LTTNG_ERR_COMMAND_CANCELLED; - futex_nto1_wake(&cmd->reply_futex); - } - pthread_mutex_unlock(&handle->cmd_queue.lock); + assert(cds_list_empty(&handle->cmd_queue.list)); pthread_mutex_destroy(&handle->cmd_queue.lock); if (handle->channel_monitoring_pipes.ust32_consumer >= 0) { -- 2.34.1