X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fnotification-thread-commands.cpp;h=2f275477b133e9c488d21beb38cdccbe6e516e6f;hb=11927a7859022cf38a4153767cc96fda4987070d;hp=b51acaf6747169e3f50de35b1d90d514c2932200;hpb=28ab034a2c3582d07d3423d2d746731f87d3969f;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/notification-thread-commands.cpp b/src/bin/lttng-sessiond/notification-thread-commands.cpp index b51acaf67..2f275477b 100644 --- a/src/bin/lttng-sessiond/notification-thread-commands.cpp +++ b/src/bin/lttng-sessiond/notification-thread-commands.cpp @@ -20,7 +20,6 @@ static void init_notification_thread_command(struct notification_thread_command *cmd) { CDS_INIT_LIST_HEAD(&cmd->cmd_list_node); - lttng_waiter_init(&cmd->reply_waiter); } static int run_command_wait(struct notification_thread_handle *handle, @@ -29,6 +28,9 @@ static int run_command_wait(struct notification_thread_handle *handle, int ret; uint64_t notification_counter = 1; + lttng::synchro::waiter command_completion_waiter; + cmd->command_completed_waker.emplace(command_completion_waiter.get_waker()); + pthread_mutex_lock(&handle->cmd_queue.lock); /* Add to queue. */ cds_list_add_tail(&cmd->cmd_list_node, &handle->cmd_queue.list); @@ -46,7 +48,8 @@ static int run_command_wait(struct notification_thread_handle *handle, } pthread_mutex_unlock(&handle->cmd_queue.lock); - lttng_waiter_wait(&cmd->reply_waiter); + command_completion_waiter.wait(); + ; return 0; error_unlock_queue: pthread_mutex_unlock(&handle->cmd_queue.lock); @@ -58,14 +61,15 @@ notification_thread_command_copy(const struct notification_thread_command *origi { struct notification_thread_command *new_cmd; - new_cmd = zmalloc(); - if (!new_cmd) { - goto end; + try { + new_cmd = new notification_thread_command; + } catch (const std::bad_alloc& e) { + ERR("Failed to allocate notification_thread_command: %s", e.what()); + return nullptr; } *new_cmd = *original_cmd; init_notification_thread_command(new_cmd); -end: return new_cmd; } @@ -96,10 +100,12 @@ static int run_command_no_wait(struct notification_thread_handle *handle, cds_list_del(&new_cmd->cmd_list_node); goto error_unlock_queue; } + pthread_mutex_unlock(&handle->cmd_queue.lock); return 0; error_unlock_queue: - free(new_cmd); + + delete new_cmd; pthread_mutex_unlock(&handle->cmd_queue.lock); error: return -1; @@ -112,7 +118,7 @@ notification_thread_command_register_trigger(struct notification_thread_handle * { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; LTTNG_ASSERT(trigger); init_notification_thread_command(&cmd); @@ -138,7 +144,7 @@ notification_thread_command_unregister_trigger(struct notification_thread_handle { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -164,7 +170,7 @@ notification_thread_command_add_session(struct notification_thread_handle *handl { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -190,7 +196,7 @@ notification_thread_command_remove_session(struct notification_thread_handle *ha { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -217,7 +223,7 @@ notification_thread_command_add_channel(struct notification_thread_handle *handl { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -243,7 +249,7 @@ enum lttng_error_code notification_thread_command_remove_channel( { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -268,7 +274,7 @@ notification_thread_command_session_rotation_ongoing(struct notification_thread_ { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -294,7 +300,7 @@ enum lttng_error_code notification_thread_command_session_rotation_completed( { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -320,7 +326,7 @@ notification_thread_command_add_tracer_event_source(struct notification_thread_h { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; LTTNG_ASSERT(tracer_event_source_fd >= 0); @@ -347,7 +353,7 @@ notification_thread_command_remove_tracer_event_source(struct notification_threa { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -370,7 +376,7 @@ enum lttng_error_code notification_thread_command_list_triggers( { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; LTTNG_ASSERT(handle); LTTNG_ASSERT(triggers); @@ -396,7 +402,7 @@ end: void notification_thread_command_quit(struct notification_thread_handle *handle) { int ret; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -410,7 +416,7 @@ int notification_thread_client_communication_update( notification_client_id id, enum client_transmission_status transmission_status) { - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -427,7 +433,7 @@ notification_thread_command_get_trigger(struct notification_thread_handle *handl { int ret; enum lttng_error_code ret_code; - struct notification_thread_command cmd = {}; + notification_thread_command cmd; init_notification_thread_command(&cmd); @@ -452,13 +458,13 @@ end: struct lttng_event_notifier_notification *lttng_event_notifier_notification_create( uint64_t tracer_token, enum lttng_domain_type domain, char *payload, size_t payload_size) { - struct lttng_event_notifier_notification *notification = NULL; + struct lttng_event_notifier_notification *notification = nullptr; LTTNG_ASSERT(domain != LTTNG_DOMAIN_NONE); LTTNG_ASSERT((payload && payload_size) || (!payload && !payload_size)); notification = zmalloc(); - if (notification == NULL) { + if (notification == nullptr) { ERR("Error allocating notification"); goto end; }