From b9e6ec43275c1a46401792b02abfb1ed380619a2 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Thu, 31 Oct 2019 11:40:27 -0400 Subject: [PATCH] Cleanup: src.ctf.lttng-live: remove usage of `bt_object` The live_viewer_connection objects are never shared and we can know that by seeing that there is no to _get_ref() in this entire component class. This commit also removes the need for the BT_OBJECT_DONT_LOG macro added by: commit 9358ceb38baa2d50a69d7ee580463a2ddba25465 Author: Philippe Proulx lib/object.h: log conditionally to `BT_OBJECT_DONT_LOG` undefined so remove that to. Signed-off-by: Francis Deslauriers Change-Id: I2b4ba20613e77048044507a93241bf7db3f58fa2 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2312 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/lib/object.h | 24 +++++-------------- src/plugins/ctf/lttng-live/lttng-live.c | 4 +++- .../ctf/lttng-live/viewer-connection.c | 23 ++++++++++-------- .../ctf/lttng-live/viewer-connection.h | 9 ------- 4 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/lib/object.h b/src/lib/object.h index 9d584c1b..c7cbb123 100644 --- a/src/lib/object.h +++ b/src/lib/object.h @@ -28,18 +28,6 @@ #include "common/assert.h" #include -/* - * Some parts of the Babeltrace project use this internal library header - * for internal reference counting. Until we make this header generic - * for the whole project, make it possible to disable logging in this - * file by defining `BT_OBJECT_DONT_LOG` because it's possible that the - * BT_LOGT() statements here won't find the log level - * (`BT_LOG_OUTPUT_LEVEL`). - */ -#if defined(BT_LOGT) && !defined(BT_OBJECT_DONT_LOG) -# define _BT_OBJECT_LOGGING_ENABLED -#endif - struct bt_object; typedef void (*bt_object_release_func)(struct bt_object *); @@ -138,7 +126,7 @@ void bt_object_set_parent(struct bt_object *child, struct bt_object *parent) BT_ASSERT_DBG(child); BT_ASSERT_DBG(child->is_shared); -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Setting object's parent: addr=%p, parent-addr=%p", child, parent); #endif @@ -185,7 +173,7 @@ void bt_object_with_parent_release_func(struct bt_object *obj) */ struct bt_object *parent = obj->parent; -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Releasing parented object: addr=%p, ref-count=%llu, " "parent-addr=%p, parent-ref-count=%llu", obj, obj->ref_count, @@ -275,7 +263,7 @@ void bt_object_get_ref_no_null_check_no_parent_check(const struct bt_object *c_o BT_ASSERT_DBG(obj); BT_ASSERT_DBG(obj->is_shared); -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Incrementing object's reference count: %llu -> %llu: " "addr=%p, cur-count=%llu, new-count=%llu", obj->ref_count, obj->ref_count + 1, @@ -294,7 +282,7 @@ void bt_object_get_ref_no_null_check(const void *c_obj) BT_ASSERT_DBG(obj->is_shared); if (G_UNLIKELY(obj->parent && bt_object_get_ref_count(obj) == 0)) { -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Incrementing object's parent's reference count: " "addr=%p, parent-addr=%p", obj, obj->parent); #endif @@ -302,7 +290,7 @@ void bt_object_get_ref_no_null_check(const void *c_obj) bt_object_get_ref_no_null_check(obj->parent); } -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Incrementing object's reference count: %llu -> %llu: " "addr=%p, cur-count=%llu, new-count=%llu", obj->ref_count, obj->ref_count + 1, @@ -321,7 +309,7 @@ void bt_object_put_ref_no_null_check(const void *c_obj) BT_ASSERT_DBG(obj->is_shared); BT_ASSERT_DBG(obj->ref_count > 0); -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Decrementing object's reference count: %llu -> %llu: " "addr=%p, cur-count=%llu, new-count=%llu", obj->ref_count, obj->ref_count - 1, diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index d12b674d..87efe7a6 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -316,7 +316,9 @@ void lttng_live_msg_iter_destroy(struct lttng_live_msg_iter *lttng_live_msg_iter g_ptr_array_free(lttng_live_msg_iter->sessions, TRUE); } - BT_OBJECT_PUT_REF_AND_RESET(lttng_live_msg_iter->viewer_connection); + if (lttng_live_msg_iter->viewer_connection) { + live_viewer_connection_destroy(lttng_live_msg_iter->viewer_connection); + } BT_ASSERT(lttng_live_msg_iter->lttng_live_comp); BT_ASSERT(lttng_live_msg_iter->lttng_live_comp->has_msg_iter); diff --git a/src/plugins/ctf/lttng-live/viewer-connection.c b/src/plugins/ctf/lttng-live/viewer-connection.c index 6fa1456f..befffb30 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.c +++ b/src/plugins/ctf/lttng-live/viewer-connection.c @@ -316,15 +316,6 @@ void lttng_live_disconnect_viewer( } } -static -void connection_release(bt_object *obj) -{ - struct live_viewer_connection *conn = - container_of(obj, struct live_viewer_connection, obj); - - live_viewer_connection_destroy(conn); -} - static int list_update_session(bt_value *results, const struct lttng_viewer_session *session, @@ -1611,7 +1602,6 @@ struct live_viewer_connection *live_viewer_connection_create( viewer_connection->self_comp = self_comp; viewer_connection->self_comp_class = self_comp_class; - bt_object_init_shared(&viewer_connection->obj, connection_release); viewer_connection->control_sock = BT_INVALID_SOCKET; viewer_connection->port = -1; viewer_connection->in_query = in_query; @@ -1646,20 +1636,33 @@ void live_viewer_connection_destroy( struct live_viewer_connection *viewer_connection) { BT_COMP_LOGI("Closing connection to url \"%s\"", viewer_connection->url->str); + + if (!viewer_connection) { + goto end; + } + lttng_live_disconnect_viewer(viewer_connection); + if (viewer_connection->url) { g_string_free(viewer_connection->url, true); } + if (viewer_connection->relay_hostname) { g_string_free(viewer_connection->relay_hostname, true); } + if (viewer_connection->target_hostname) { g_string_free(viewer_connection->target_hostname, true); } + if (viewer_connection->session_name) { g_string_free(viewer_connection->session_name, true); } + g_free(viewer_connection); bt_socket_fini(); + +end: + return; } diff --git a/src/plugins/ctf/lttng-live/viewer-connection.h b/src/plugins/ctf/lttng-live/viewer-connection.h index fcdd4c4d..c42c16b0 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.h +++ b/src/plugins/ctf/lttng-live/viewer-connection.h @@ -30,14 +30,6 @@ #include "common/macros.h" #include "compat/socket.h" -/* - * FIXME: This is an internal Babeltrace library header; it is not meant - * to be generic as it is now. Make sure this included code does not - * log because it won't find our local log level. - */ -#define BT_OBJECT_DONT_LOG -#include "lib/object.h" - #define LTTNG_DEFAULT_NETWORK_VIEWER_PORT 5344 #define LTTNG_LIVE_MAJOR 2 @@ -46,7 +38,6 @@ struct lttng_live_component; struct live_viewer_connection { - bt_object obj; bt_logging_level log_level; bt_self_component *self_comp; bt_self_component_class *self_comp_class; -- 2.34.1