Launch the timer thread using lttng_thread
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 30 Nov 2018 17:12:12 +0000 (12:12 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 5 Dec 2018 17:25:11 +0000 (12:25 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/main.c
src/bin/lttng-sessiond/timer.c
src/bin/lttng-sessiond/timer.h

index 0c207309dbb0714ed24c78e55c8072b1f15154b1..c82e0095bc1e476b015a164a61975a661d39ff95 100644 (file)
@@ -194,7 +194,6 @@ static pthread_t kernel_thread;
 static pthread_t dispatch_thread;
 static pthread_t agent_reg_thread;
 static pthread_t load_session_thread;
-static pthread_t timer_thread;
 
 /*
  * UST registration command queue. This queue is tied with a futex and uses a N
@@ -5492,9 +5491,8 @@ int main(int argc, char **argv)
        struct lttng_pipe *ust32_channel_monitor_pipe = NULL,
                        *ust64_channel_monitor_pipe = NULL,
                        *kernel_channel_monitor_pipe = NULL;
-       bool timer_thread_launched = false;
        struct lttng_thread *ht_cleanup_thread = NULL;
-       struct timer_thread_parameters timer_thread_ctx;
+       struct timer_thread_parameters timer_thread_parameters;
        /* Rotation thread handle. */
        struct rotation_thread_handle *rotation_thread_handle = NULL;
        /* Queue of rotation jobs populated by the sessiond-timer. */
@@ -5693,7 +5691,8 @@ int main(int argc, char **argv)
                retval = -1;
                goto exit_init_data;
        }
-       timer_thread_ctx.rotation_thread_job_queue = rotation_timer_queue;
+       timer_thread_parameters.rotation_thread_job_queue =
+                       rotation_timer_queue;
 
        ust64_channel_monitor_pipe = lttng_pipe_open(0);
        if (!ust64_channel_monitor_pipe) {
@@ -5862,20 +5861,13 @@ int main(int argc, char **argv)
        if (!launch_notification_thread(notification_thread_handle)) {
                retval = -1;
                goto exit_notification;
-
        }
 
        /* Create timer thread. */
-       ret = pthread_create(&timer_thread, default_pthread_attr(),
-                       timer_thread_func, &timer_thread_ctx);
-       if (ret) {
-               errno = ret;
-               PERROR("pthread_create timer");
+       if (!launch_timer_thread(&timer_thread_parameters)) {
                retval = -1;
-               stop_threads();
                goto exit_notification;
        }
-       timer_thread_launched = true;
 
        /* rotation_thread_data acquires the pipes' read side. */
        rotation_thread_handle = rotation_thread_handle_create(
@@ -6089,16 +6081,6 @@ exit_init_data:
         */
        rcu_barrier();
 
-       if (timer_thread_launched) {
-               timer_exit();
-               ret = pthread_join(timer_thread, &status);
-               if (ret) {
-                       errno = ret;
-                       PERROR("pthread_join timer thread");
-                       retval = -1;
-               }
-       }
-
        if (ht_cleanup_thread) {
                lttng_thread_shutdown(ht_cleanup_thread);
                lttng_thread_put(ht_cleanup_thread);
index fa5e95cf194721bd5ff812ad1ea67fac9a312608..9915767657fdbdc790d4b8568cd6ecb710b8a40d 100644 (file)
@@ -24,6 +24,7 @@
 #include "timer.h"
 #include "health-sessiond.h"
 #include "rotation-thread.h"
+#include "thread.h"
 
 #define LTTNG_SESSIOND_SIG_QS                          SIGRTMIN + 10
 #define LTTNG_SESSIOND_SIG_EXIT                                SIGRTMIN + 11
@@ -344,7 +345,8 @@ int timer_signal_init(void)
 /*
  * This thread is the sighandler for the timer signals.
  */
-void *timer_thread_func(void *data)
+static
+void *thread_timer(void *data)
 {
        int signr;
        sigset_t mask;
@@ -414,7 +416,27 @@ end:
        return NULL;
 }
 
-void timer_exit(void)
+static
+bool shutdown_timer_thread(void *data)
+{
+       return kill(getpid(), LTTNG_SESSIOND_SIG_EXIT) == 0;
+}
+
+bool launch_timer_thread(
+               struct timer_thread_parameters *timer_thread_parameters)
 {
-       kill(getpid(), LTTNG_SESSIOND_SIG_EXIT);
+       struct lttng_thread *thread;
+
+       thread = lttng_thread_create("Timer",
+                       thread_timer,
+                       shutdown_timer_thread,
+                       NULL,
+                       timer_thread_parameters);
+       if (!thread) {
+               goto error;
+       }
+       lttng_thread_put(thread);
+       return true;
+error:
+       return false;
 }
index 83be4873ce3381942b0e69ea878331dbbe088109..1e8178cae5914a6a9348f68f369351af3adb51d0 100644 (file)
@@ -20,6 +20,7 @@
 #define SESSIOND_TIMER_H
 
 #include <pthread.h>
+#include <stdbool.h>
 
 #include "session.h"
 
@@ -28,9 +29,6 @@ struct timer_thread_parameters {
 };
 
 int timer_signal_init(void);
-void *timer_thread_func(void *data);
-
-void timer_exit(void);
 
 /* Start a session's rotation pending check timer (one-shot mode). */
 int timer_session_rotation_pending_check_start(struct ltt_session *session,
@@ -44,4 +42,7 @@ int timer_session_rotation_schedule_timer_start(struct ltt_session *session,
 /* Stop a session's rotation schedule timer. */
 int timer_session_rotation_schedule_timer_stop(struct ltt_session *session);
 
+bool launch_timer_thread(
+               struct timer_thread_parameters *timer_thread_parameters);
+
 #endif /* SESSIOND_TIMER_H */
This page took 0.030183 seconds and 5 git commands to generate.