Convert ust_app_session to c++
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 18 Aug 2022 20:29:25 +0000 (16:29 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 19 Aug 2022 15:53:13 +0000 (11:53 -0400)
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 <jonathan.rajotte-julien@efficios.com>
Change-Id: I3536444e002f1311b851e2333ff5f8fc4a5904dd

src/bin/lttng-sessiond/ust-app.cpp
src/bin/lttng-sessiond/ust-app.hpp

index 9690115d66c56ca83b06f6adb6e92e888249ec00..e6f251f40cde2bc0b63e683d8085e82635b2485d 100644 (file)
@@ -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<ust_app_session>();
+       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);
 
index c48e2b9e25b97f95e745b4cbd47d667583c0eb26..5007d807b63c52f25b59c5cceb6c2eb660263189 100644 (file)
@@ -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]{};
 };
 
 /*
This page took 0.0404 seconds and 5 git commands to generate.