From: Jonathan Rajotte Date: Thu, 18 Aug 2022 20:29:25 +0000 (-0400) Subject: Convert ust_app_session to c++ X-Git-Url: https://git.efficios.com/?a=commitdiff_plain;h=604f8e58fee3e1add1b0a2dcb542844983cd3075;p=deliverable%2Flttng-tools.git Convert ust_app_session to c++ This is a minimal patch to move the ust_app_session struct to c++ style. This will allow us to add complex type in the struct later on (such as unique_ptr/shared_ptr etc). Use default member initialization when possible. Signed-off-by: Jonathan Rajotte Change-Id: I3536444e002f1311b851e2333ff5f8fc4a5904dd --- diff --git a/src/bin/lttng-sessiond/ust-app.cpp b/src/bin/lttng-sessiond/ust-app.cpp index 9690115d6..e6f251f40 100644 --- a/src/bin/lttng-sessiond/ust-app.cpp +++ b/src/bin/lttng-sessiond/ust-app.cpp @@ -905,7 +905,7 @@ void delete_ust_app_session_rcu(struct rcu_head *head) lttng::utils::container_of(head, &ust_app_session::rcu_head); lttng_ht_destroy(ua_sess->channels); - free(ua_sess); + delete (ua_sess); } /* @@ -1172,14 +1172,12 @@ struct ust_app_session *alloc_ust_app_session(void) struct ust_app_session *ua_sess; /* Init most of the default value by allocating and zeroing */ - ua_sess = zmalloc(); + ua_sess = new ust_app_session(); if (ua_sess == NULL) { PERROR("malloc"); goto error_free; } - ua_sess->handle = -1; - ua_sess->channels = lttng_ht_new(0, LTTNG_HT_TYPE_STRING); ua_sess->metadata_attr.type = LTTNG_UST_ABI_CHAN_METADATA; pthread_mutex_init(&ua_sess->lock, NULL); diff --git a/src/bin/lttng-sessiond/ust-app.hpp b/src/bin/lttng-sessiond/ust-app.hpp index c48e2b9e2..5007d807b 100644 --- a/src/bin/lttng-sessiond/ust-app.hpp +++ b/src/bin/lttng-sessiond/ust-app.hpp @@ -195,28 +195,28 @@ struct ust_app_session { */ pthread_mutex_t lock; - int enabled; + int enabled{}; /* started: has the session been in started state at any time ? */ - int started; /* allows detection of start vs restart. */ - int handle; /* used has unique identifier for app session */ + int started{}; /* allows detection of start vs restart. */ + int handle{-1}; /* used has unique identifier for app session */ - bool deleted; /* Session deleted flag. Check with lock held. */ + bool deleted{false}; /* Session deleted flag. Check with lock held. */ /* * Tracing session ID. Multiple ust app session can have the same tracing * session id making this value NOT unique to the object. */ - uint64_t tracing_id; - uint64_t id; /* Unique session identifier */ - struct lttng_ht *channels; /* Registered channels */ - struct lttng_ht_node_u64 node; + uint64_t tracing_id{}; + uint64_t id{}; /* Unique session identifier */ + struct lttng_ht *channels{lttng_ht_new(0, LTTNG_HT_TYPE_STRING)}; /* Registered channels */ + struct lttng_ht_node_u64 node {}; /* * Node indexed by UST session object descriptor (handle). Stored in the * ust_sessions_objd hash table in the ust_app object. */ struct lttng_ht_node_ulong ust_objd_node; /* Starts with 'ust'; no leading slash. */ - char path[PATH_MAX]; + char path[PATH_MAX]{}; /* UID/GID of the application owning the session */ struct lttng_credentials real_credentials; /* Effective UID and GID. Same as the tracing session. */ @@ -226,21 +226,21 @@ struct ust_app_session { * Once at least *one* session is created onto the application, the * corresponding consumer is set so we can use it on unregistration. */ - struct consumer_output *consumer; - enum lttng_buffer_type buffer_type; + struct consumer_output *consumer{nullptr}; + enum lttng_buffer_type buffer_type { LTTNG_BUFFER_PER_PID }; /* ABI of the session. Same value as the application. */ - uint32_t bits_per_long; + uint32_t bits_per_long{}; /* For delayed reclaim */ - struct rcu_head rcu_head; + struct rcu_head rcu_head {}; /* If the channel's streams have to be outputed or not. */ - unsigned int output_traces; - unsigned int live_timer_interval; /* usec */ + unsigned int output_traces{}; + unsigned int live_timer_interval{}; /* usec */ /* Metadata channel attributes. */ - struct lttng_ust_ctl_consumer_channel_attr metadata_attr; + struct lttng_ust_ctl_consumer_channel_attr metadata_attr {}; - char root_shm_path[PATH_MAX]; - char shm_path[PATH_MAX]; + char root_shm_path[PATH_MAX]{}; + char shm_path[PATH_MAX]{}; }; /*