Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / bin / lttng-sessiond / thread.cpp
index 9ce539b816a99732cf0a6c3ed5c3901584e8e44a..4077f460ef4c11dc31c5ce10b26ca2ed75348f06 100644 (file)
@@ -6,20 +6,24 @@
  */
 
 #include "thread.hpp"
+
+#include <common/defaults.hpp>
+#include <common/error.hpp>
+#include <common/macros.hpp>
+
+#include <pthread.h>
 #include <urcu/list.h>
 #include <urcu/ref.h>
-#include <pthread.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;
@@ -40,8 +44,7 @@ struct lttng_thread {
        void *data;
 };
 
-static
-void lttng_thread_destroy(struct lttng_thread *thread)
+static void lttng_thread_destroy(struct lttng_thread *thread)
 {
        if (thread->cleanup) {
                thread->cleanup(thread->data);
@@ -49,14 +52,12 @@ void lttng_thread_destroy(struct lttng_thread *thread)
        free(thread);
 }
 
-static
-void lttng_thread_release(struct urcu_ref *ref)
+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
-void *launch_thread(void *data)
+static void *launch_thread(void *data)
 {
        void *ret;
        struct lttng_thread *thread = (struct lttng_thread *) data;
@@ -69,15 +70,15 @@ void *launch_thread(void *data)
 }
 
 struct lttng_thread *lttng_thread_create(const char *name,
-               lttng_thread_entry_point entry,
-               lttng_thread_shutdown_cb shutdown,
-               lttng_thread_cleanup_cb cleanup,
-               void *thread_data)
+                                        lttng_thread_entry_point entry,
+                                        lttng_thread_shutdown_cb shutdown,
+                                        lttng_thread_cleanup_cb cleanup,
+                                        void *thread_data)
 {
        int ret;
        struct lttng_thread *thread;
 
-       thread = (lttng_thread *) zmalloc(sizeof(*thread));
+       thread = zmalloc<lttng_thread>();
        if (!thread) {
                goto error_alloc;
        }
@@ -103,8 +104,7 @@ struct lttng_thread *lttng_thread_create(const char *name,
        cds_list_add(&thread->node, &thread_list.head);
        (void) lttng_thread_get(thread);
 
-       ret = pthread_create(&thread->thread, default_pthread_attr(),
-                       launch_thread, thread);
+       ret = pthread_create(&thread->thread, default_pthread_attr(), launch_thread, thread);
        if (ret) {
                PERROR("Failed to create \"%s\" thread", thread->name);
                goto error_pthread_create;
@@ -121,7 +121,7 @@ error_pthread_create:
        /* Release initial reference. */
        lttng_thread_put(thread);
 error_alloc:
-       return NULL;
+       return nullptr;
 }
 
 bool lttng_thread_get(struct lttng_thread *thread)
@@ -143,8 +143,7 @@ const char *lttng_thread_get_name(const struct lttng_thread *thread)
        return thread->name;
 }
 
-static
-bool _lttng_thread_shutdown(struct lttng_thread *thread)
+static bool _lttng_thread_shutdown(struct lttng_thread *thread)
 {
        int ret;
        void *status;
@@ -184,12 +183,12 @@ bool lttng_thread_shutdown(struct lttng_thread *thread)
        return result;
 }
 
-void lttng_thread_list_shutdown_orphans(void)
+void lttng_thread_list_shutdown_orphans()
 {
        struct lttng_thread *thread, *tmp;
 
        pthread_mutex_lock(&thread_list.lock);
-       cds_list_for_each_entry_safe(thread, tmp, &thread_list.head, node) {
+       cds_list_for_each_entry_safe (thread, tmp, &thread_list.head, node) {
                bool result;
                const long ref = uatomic_read(&thread->ref.refcount);
 
This page took 0.024591 seconds and 4 git commands to generate.