Convert ltt_ust_session to c++
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 14 Apr 2022 20:01:25 +0000 (16:01 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 19 Aug 2022 15:49:39 +0000 (11:49 -0400)
This is a minimal patch to move the ltt_ust_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: I2578fa24fde8de0728d20a938aa55e2a6ad7a161

src/bin/lttng-sessiond/client.cpp
src/bin/lttng-sessiond/trace-ust.cpp
src/bin/lttng-sessiond/trace-ust.hpp

index aafbd919ce07e73d0b071cac3ec3327996498201..3ec4c0d0add5c174000ffd61ba569287d89178d6 100644 (file)
@@ -538,7 +538,7 @@ static int create_ust_session(struct ltt_session *session,
        return LTTNG_OK;
 
 error:
-       free(lus);
+       delete (lus);
        session->ust_session = NULL;
        return ret;
 }
index 4a3e74de7792b8bc0b195b98f8bc15d9db9e5a10..9ecfddc785bb0b013230ad8fa8e3e006feb68d35 100644 (file)
@@ -272,10 +272,10 @@ struct ltt_ust_session *trace_ust_create_session(uint64_t session_id)
 {
        struct ltt_ust_session *lus;
 
-       /* Allocate a new ltt ust session */
-       lus = zmalloc<ltt_ust_session>();
-       if (lus == NULL) {
-               PERROR("create ust session zmalloc");
+       try {
+               lus = new ltt_ust_session();
+       } catch (const std::exception& ex) {
+               ERR("Failed to create lttng_ust_session: %s", ex.what());
                goto error_alloc;
        }
 
@@ -335,7 +335,7 @@ error:
        process_attr_tracker_destroy(lus->tracker_vgid);
        lttng_ht_destroy(lus->domain_global.channels);
        lttng_ht_destroy(lus->agents);
-       free(lus);
+       delete (lus);
 error_alloc:
        return NULL;
 }
@@ -1465,5 +1465,5 @@ void trace_ust_destroy_session(struct ltt_ust_session *session)
 void trace_ust_free_session(struct ltt_ust_session *session)
 {
        consumer_output_put(session->consumer);
-       free(session);
+       delete (session);
 }
index 38662ec5888de3fc8d6381fe5afea1c9716de25d..fcb16d330b6e0be76459af70a0725a1e732ec7ba 100644 (file)
@@ -92,55 +92,58 @@ struct ust_id_tracker {
 
 /* UST session */
 struct ltt_ust_session {
-       uint64_t id;    /* Unique identifier of session */
-       struct ltt_ust_domain_global domain_global;
+       ltt_ust_session() = default;
+       ~ltt_ust_session() = default;
+
+       uint64_t id{}; /* Unique identifier of session */
+       struct ltt_ust_domain_global domain_global {};
        /* Hash table of agent indexed by agent domain. */
-       struct lttng_ht *agents;
+       struct lttng_ht *agents{};
        /* UID/GID of the user owning the session */
-       uid_t uid;
-       gid_t gid;
+       uid_t uid{};
+       gid_t gid{};
        /* Is the session active meaning has is been started or stopped. */
-       unsigned int active:1;
-       struct consumer_output *consumer;
+       bool active{false};
+       struct consumer_output *consumer{};
        /* Sequence number for filters so the tracer knows the ordering. */
-       uint64_t filter_seq_num;
+       uint64_t filter_seq_num{};
        /* This indicates which type of buffer this session is set for. */
-       enum lttng_buffer_type buffer_type;
+       enum lttng_buffer_type buffer_type {};
        /* If set to 1, the buffer_type can not be changed anymore. */
-       int buffer_type_changed;
+       int buffer_type_changed{};
        /* For per UID buffer, every buffer reg object is kept of this session */
-       struct cds_list_head buffer_reg_uid_list;
+       struct cds_list_head buffer_reg_uid_list {};
        /* Next channel ID available for a newly registered channel. */
-       uint64_t next_channel_id;
+       uint64_t next_channel_id{};
        /* Once this value reaches UINT32_MAX, no more id can be allocated. */
-       uint64_t used_channel_id;
+       uint64_t used_channel_id{};
        /* Tell or not if the session has to output the traces. */
-       unsigned int output_traces;
-       unsigned int snapshot_mode;
-       unsigned int has_non_default_channel;
-       unsigned int live_timer_interval;       /* usec */
+       unsigned int output_traces{};
+       unsigned int snapshot_mode{};
+       unsigned int has_non_default_channel{};
+       unsigned int live_timer_interval{}; /* usec */
 
        /* Metadata channel attributes. */
-       struct lttng_ust_abi_channel_attr metadata_attr;
+       struct lttng_ust_abi_channel_attr metadata_attr {};
 
        /*
         * Path where to keep the shared memory files.
         */
-       char root_shm_path[PATH_MAX];
-       char shm_path[PATH_MAX];
+       char root_shm_path[PATH_MAX]{};
+       char shm_path[PATH_MAX]{};
 
        /* Current trace chunk of the ltt_session. */
-       struct lttng_trace_chunk *current_trace_chunk;
+       struct lttng_trace_chunk *current_trace_chunk{};
 
        /* Trackers used for actual lookup on app registration. */
-       struct ust_id_tracker vpid_tracker;
-       struct ust_id_tracker vuid_tracker;
-       struct ust_id_tracker vgid_tracker;
+       struct ust_id_tracker vpid_tracker {};
+       struct ust_id_tracker vuid_tracker {};
+       struct ust_id_tracker vgid_tracker {};
 
        /* Tracker list of keys requested by users. */
-       struct process_attr_tracker *tracker_vpid;
-       struct process_attr_tracker *tracker_vuid;
-       struct process_attr_tracker *tracker_vgid;
+       struct process_attr_tracker *tracker_vpid{};
+       struct process_attr_tracker *tracker_vuid{};
+       struct process_attr_tracker *tracker_vgid{};
 };
 
 /*
This page took 0.033314 seconds and 5 git commands to generate.