From: Jérémie Galarneau Date: Wed, 17 May 2017 20:03:13 +0000 (-0400) Subject: Fix: use lttng_waiter instead of futex in notification thread X-Git-Tag: v2.11.0-rc1~578 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8ada111f6d3ab40d1c33cf1a7b2546de9a47d1d5;p=lttng-tools.git Fix: use lttng_waiter instead of futex in notification thread Signed-off-by: Jérémie Galarneau --- 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) {