common: replace container_of with a C++ safe implementation
[lttng-tools.git] / src / bin / lttng-sessiond / thread.cpp
index 446a8c9d2e52276dd5972cf869884c57ec22bb78..fd9136fe5562b4e5acee6a70bef36061572b38c0 100644 (file)
@@ -5,21 +5,23 @@
  *
  */
 
-#include "thread.h"
+#include "thread.hpp"
 #include <urcu/list.h>
 #include <urcu/ref.h>
 #include <pthread.h>
-#include <common/macros.h>
-#include <common/error.h>
-#include <common/defaults.h>
+#include <common/macros.hpp>
+#include <common/error.hpp>
+#include <common/defaults.hpp>
 
-static struct thread_list {
+namespace {
+struct thread_list {
        struct cds_list_head head;
        pthread_mutex_t lock;
 } thread_list = {
        .head = CDS_LIST_HEAD_INIT(thread_list.head),
        .lock = PTHREAD_MUTEX_INITIALIZER,
 };
+} /* namespace */
 
 struct lttng_thread {
        struct urcu_ref ref;
@@ -52,7 +54,7 @@ void lttng_thread_destroy(struct lttng_thread *thread)
 static
 void lttng_thread_release(struct urcu_ref *ref)
 {
-       lttng_thread_destroy(container_of(ref, struct lttng_thread, ref));
+       lttng_thread_destroy(lttng::utils::container_of(ref, &lttng_thread::ref));
 }
 
 static
@@ -77,7 +79,7 @@ struct lttng_thread *lttng_thread_create(const char *name,
        int ret;
        struct lttng_thread *thread;
 
-       thread = (lttng_thread *) zmalloc(sizeof(*thread));
+       thread = zmalloc<lttng_thread>();
        if (!thread) {
                goto error_alloc;
        }
This page took 0.023536 seconds and 4 git commands to generate.