Add type-checked versions of allocation and deallocations functions
[lttng-tools.git] / src / common / consumer / consumer.cpp
index f26ccd71a9ff57bc3eda8c2b97cc58ae5ec0a414..9393e6cc29af21a8c3b8072ffd42eb6a0ae14b3e 100644 (file)
@@ -7,43 +7,42 @@
  *
  */
 
-#include "common/index/ctf-index.h"
-#include <stdint.h>
 #define _LGPL_SOURCE
+#include <inttypes.h>
 #include <poll.h>
 #include <pthread.h>
+#include <signal.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <inttypes.h>
-#include <signal.h>
 
-#include <bin/lttng-consumerd/health-consumerd.h>
-#include <common/common.h>
-#include <common/utils.h>
-#include <common/time.h>
-#include <common/compat/poll.h>
-#include <common/compat/endian.h>
-#include <common/index/index.h>
-#include <common/kernel-ctl/kernel-ctl.h>
-#include <common/sessiond-comm/relayd.h>
-#include <common/sessiond-comm/sessiond-comm.h>
-#include <common/kernel-consumer/kernel-consumer.h>
-#include <common/relayd/relayd.h>
-#include <common/ust-consumer/ust-consumer.h>
-#include <common/consumer/consumer-timer.h>
-#include <common/consumer/consumer.h>
-#include <common/consumer/consumer-stream.h>
-#include <common/consumer/consumer-testpoint.h>
-#include <common/align.h>
-#include <common/consumer/consumer-metadata-cache.h>
-#include <common/trace-chunk.h>
-#include <common/trace-chunk-registry.h>
-#include <common/string-utils/format.h>
-#include <common/dynamic-array.h>
+#include <bin/lttng-consumerd/health-consumerd.hpp>
+#include <common/align.hpp>
+#include <common/common.hpp>
+#include <common/compat/endian.hpp>
+#include <common/compat/poll.hpp>
+#include <common/consumer/consumer-metadata-cache.hpp>
+#include <common/consumer/consumer-stream.hpp>
+#include <common/consumer/consumer-testpoint.hpp>
+#include <common/consumer/consumer-timer.hpp>
+#include <common/consumer/consumer.hpp>
+#include <common/dynamic-array.hpp>
+#include <common/index/ctf-index.hpp>
+#include <common/index/index.hpp>
+#include <common/kernel-consumer/kernel-consumer.hpp>
+#include <common/kernel-ctl/kernel-ctl.hpp>
+#include <common/relayd/relayd.hpp>
+#include <common/sessiond-comm/relayd.hpp>
+#include <common/sessiond-comm/sessiond-comm.hpp>
+#include <common/string-utils/format.hpp>
+#include <common/time.hpp>
+#include <common/trace-chunk-registry.hpp>
+#include <common/trace-chunk.hpp>
+#include <common/ust-consumer/ust-consumer.hpp>
+#include <common/utils.hpp>
 
 lttng_consumer_global_data the_consumer_data;
 
@@ -663,7 +662,7 @@ static struct consumer_relayd_sock_pair *consumer_allocate_relayd_sock_pair(
                goto error;
        }
 
-       obj = (consumer_relayd_sock_pair *) zmalloc(sizeof(struct consumer_relayd_sock_pair));
+       obj = zmalloc<consumer_relayd_sock_pair>();
        if (obj == NULL) {
                PERROR("zmalloc relayd sock");
                goto error;
@@ -1030,7 +1029,7 @@ struct lttng_consumer_channel *consumer_allocate_channel(uint64_t key,
                }
        }
 
-       channel = (lttng_consumer_channel *) zmalloc(sizeof(*channel));
+       channel = zmalloc<lttng_consumer_channel>();
        if (channel == NULL) {
                PERROR("malloc struct lttng_consumer_channel");
                goto end;
@@ -1426,7 +1425,7 @@ struct lttng_consumer_local_data *lttng_consumer_create(
                        the_consumer_data.type == type);
        the_consumer_data.type = type;
 
-       ctx = (lttng_consumer_local_data *) zmalloc(sizeof(struct lttng_consumer_local_data));
+       ctx = zmalloc<lttng_consumer_local_data>();
        if (ctx == NULL) {
                PERROR("allocating context");
                goto error;
@@ -2562,7 +2561,7 @@ void *consumer_thread_data_poll(void *data)
 
        health_code_update();
 
-       local_stream = (lttng_consumer_stream **) zmalloc(sizeof(struct lttng_consumer_stream *));
+       local_stream = zmalloc<lttng_consumer_stream *>();
        if (local_stream == NULL) {
                PERROR("local_stream malloc");
                goto end;
@@ -2587,18 +2586,14 @@ void *consumer_thread_data_poll(void *data)
                        local_stream = NULL;
 
                        /* Allocate for all fds */
-                       pollfd = (struct pollfd *) zmalloc((the_consumer_data.stream_count +
-                                                        nb_pipes_fd) *
-                                       sizeof(struct pollfd));
+                       pollfd = calloc<struct pollfd>(the_consumer_data.stream_count + nb_pipes_fd);
                        if (pollfd == NULL) {
                                PERROR("pollfd malloc");
                                pthread_mutex_unlock(&the_consumer_data.lock);
                                goto end;
                        }
 
-                       local_stream = (lttng_consumer_stream **) zmalloc((the_consumer_data.stream_count +
-                                                              nb_pipes_fd) *
-                                       sizeof(struct lttng_consumer_stream *));
+                       local_stream = calloc<lttng_consumer_stream *>(the_consumer_data.stream_count + nb_pipes_fd);
                        if (local_stream == NULL) {
                                PERROR("local_stream malloc");
                                pthread_mutex_unlock(&the_consumer_data.lock);
This page took 0.02533 seconds and 4 git commands to generate.