#include "health-sessiond.h"
#include "testpoint.h"
#include "utils.h"
+#include "ht-cleanup.h"
-int ht_cleanup_quit_pipe[2] = { -1, -1 };
+static int ht_cleanup_quit_pipe[2] = { -1, -1 };
/*
* Check if the ht_cleanup thread quit pipe was triggered.
return ret;
}
+static void cleanup_ht_cleanup_thread(void *data)
+{
+ utils_close_pipe(ht_cleanup_quit_pipe);
+ utils_close_pipe(ht_cleanup_pipe);
+}
+
static void *thread_ht_cleanup(void *data)
{
int ret, i, pollfd, err = -1;
return NULL;
}
-int init_ht_cleanup_thread(pthread_t *thread)
+static bool shutdown_ht_cleanup_thread(void *data)
+{
+ int ret;
+
+ ret = notify_thread_pipe(ht_cleanup_quit_pipe[1]);
+ if (ret < 0) {
+ ERR("write error on ht_cleanup quit pipe");
+ goto end;
+ }
+end:
+ return ret;
+}
+
+struct lttng_thread *launch_ht_cleanup_thread(void)
{
int ret;
+ struct lttng_thread *thread;
ret = init_pipe(ht_cleanup_pipe);
if (ret) {
ret = init_pipe(ht_cleanup_quit_pipe);
if (ret) {
- goto error_quit_pipe;
+ goto error;
}
- ret = pthread_create(thread, default_pthread_attr(), thread_ht_cleanup,
+ thread = lttng_thread_create("HT cleanup",
+ thread_ht_cleanup,
+ shutdown_ht_cleanup_thread,
+ cleanup_ht_cleanup_thread,
NULL);
- if (ret) {
- errno = ret;
- PERROR("pthread_create ht_cleanup");
- goto error_thread;
+ if (!thread) {
+ ret = -1;
+ goto error;
}
-
+ return thread;
error:
- return ret;
-
-error_thread:
- utils_close_pipe(ht_cleanup_quit_pipe);
-error_quit_pipe:
- utils_close_pipe(ht_cleanup_pipe);
- return ret;
-}
-
-int fini_ht_cleanup_thread(pthread_t *thread)
-{
- int ret;
-
- ret = notify_thread_pipe(ht_cleanup_quit_pipe[1]);
- if (ret < 0) {
- ERR("write error on ht_cleanup quit pipe");
- goto end;
- }
-
- ret = pthread_join(*thread, NULL);
- if (ret) {
- errno = ret;
- PERROR("pthread_join ht cleanup thread");
- }
- utils_close_pipe(ht_cleanup_pipe);
- utils_close_pipe(ht_cleanup_quit_pipe);
-end:
- return ret;
+ cleanup_ht_cleanup_thread(NULL);
+ return NULL;
}
#define _LTTNG_HT_CLEANUP_H
#include <pthread.h>
+#include "thread.h"
-int init_ht_cleanup_thread(pthread_t *thread);
-int fini_ht_cleanup_thread(pthread_t *thread);
+struct lttng_thread *launch_ht_cleanup_thread(void);
#endif /* _LTTNG_HT_CLEANUP_H */
#include "ht-cleanup.h"
#include "sessiond-config.h"
#include "timer.h"
+#include "thread.h"
static const char *help_msg =
#ifdef LTTNG_EMBED_HELP
static pthread_t kernel_thread;
static pthread_t dispatch_thread;
static pthread_t health_thread;
-static pthread_t ht_cleanup_thread;
static pthread_t agent_reg_thread;
static pthread_t load_session_thread;
static pthread_t notification_thread;
bool notification_thread_launched = false;
bool rotation_thread_launched = false;
bool timer_thread_launched = false;
+ struct lttng_thread *ht_cleanup_thread = NULL;
struct timer_thread_parameters timer_thread_ctx;
/* Queue of rotation jobs populated by the sessiond-timer. */
struct rotation_thread_timer_queue *rotation_timer_queue = NULL;
}
/* Create thread to clean up RCU hash tables */
- if (init_ht_cleanup_thread(&ht_cleanup_thread)) {
+ ht_cleanup_thread = launch_ht_cleanup_thread();
+ if (!ht_cleanup_thread) {
retval = -1;
goto exit_ht_cleanup;
}
PERROR("pthread_join health thread");
retval = -1;
}
+ lttng_thread_list_shutdown_orphans();
exit_health:
exit_init_data:
}
}
+ if (ht_cleanup_thread) {
+ lttng_thread_shutdown(ht_cleanup_thread);
+ lttng_thread_put(ht_cleanup_thread);
+ }
+
/*
* After the rotation and timer thread have quit, we can safely destroy
* the rotation_timer_queue.
rcu_thread_offline();
rcu_unregister_thread();
- ret = fini_ht_cleanup_thread(&ht_cleanup_thread);
- if (ret) {
- retval = -1;
- }
lttng_pipe_destroy(ust32_channel_monitor_pipe);
lttng_pipe_destroy(ust64_channel_monitor_pipe);
lttng_pipe_destroy(kernel_channel_monitor_pipe);
$(top_builddir)/src/bin/lttng-sessiond/globals.$(OBJEXT) \
$(top_builddir)/src/bin/lttng-sessiond/thread-utils.$(OBJEXT) \
$(top_builddir)/src/bin/lttng-sessiond/process-utils.$(OBJEXT) \
+ $(top_builddir)/src/bin/lttng-sessiond/thread.$(OBJEXT) \
$(top_builddir)/src/common/libcommon.la \
$(top_builddir)/src/common/testpoint/libtestpoint.la \
$(top_builddir)/src/common/compat/libcompat.la \
#include <bin/lttng-sessiond/ust-app.h>
#include <bin/lttng-sessiond/ht-cleanup.h>
#include <bin/lttng-sessiond/health-sessiond.h>
+#include <bin/lttng-sessiond/thread.h>
#include <common/sessiond-comm/sessiond-comm.h>
#include <common/common.h>
struct health_app *health_sessiond;
static struct ltt_session_list *session_list;
-static pthread_t ht_cleanup_thread;
/* For error.h */
int lttng_opt_quiet = 1;
int main(int argc, char **argv)
{
+ struct lttng_thread *ht_cleanup_thread;
+
plan_tests(NUM_TESTS);
health_sessiond = health_app_create(NR_HEALTH_SESSIOND_TYPES);
- assert(!init_ht_cleanup_thread(&ht_cleanup_thread));
+ ht_cleanup_thread = launch_ht_cleanup_thread();
+ assert(ht_cleanup_thread);
+ lttng_thread_put(ht_cleanup_thread);
diag("Sessions unit tests");
test_large_session_number();
rcu_unregister_thread();
- assert(!fini_ht_cleanup_thread(&ht_cleanup_thread));
+ lttng_thread_list_shutdown_orphans();
return exit_status();
}