tests: Add C versions of gen-ust-events-constructor
[lttng-tools.git] / src / bin / lttng-sessiond / rotation-thread.hpp
CommitLineData
db66e574 1/*
ab5be9fa
MJ
2 * Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
db66e574 4 *
ab5be9fa 5 * SPDX-License-Identifier: GPL-2.0-only
db66e574 6 *
db66e574
JD
7 */
8
9#ifndef ROTATION_THREAD_H
10#define ROTATION_THREAD_H
11
0038180d
JG
12#include "notification-thread.hpp"
13#include "session.hpp"
14
c9e313bc 15#include <common/compat/poll.hpp>
0038180d 16#include <common/eventfd.hpp>
c9e313bc 17#include <common/hashtable/hashtable.hpp>
0038180d
JG
18#include <common/make-unique-wrapper.hpp>
19#include <common/pipe.hpp>
20
21#include <lttng/domain.h>
22#include <lttng/notification/channel-internal.hpp>
23
24#include <memory>
db66e574 25#include <pthread.h>
90936dcf 26#include <semaphore.h>
0038180d
JG
27#include <urcu.h>
28#include <urcu/list.h>
29#include <urcu/rculfhash.h>
db66e574 30
0038180d
JG
31namespace lttng {
32namespace sessiond {
90936dcf 33
28f23191 34enum class rotation_thread_job_type { SCHEDULED_ROTATION, CHECK_PENDING_ROTATION };
90936dcf 35
92816cc3 36struct rotation_thread_timer_queue;
90936dcf 37
0038180d
JG
38class rotation_thread {
39public:
40 using uptr = std::unique_ptr<rotation_thread>;
db66e574 41
0038180d 42 rotation_thread(rotation_thread_timer_queue& rotation_timer_queue,
28f23191 43 notification_thread_handle& notification_thread_handle);
e761773d
JG
44 rotation_thread(const rotation_thread&) = delete;
45 rotation_thread(rotation_thread&&) = delete;
46 rotation_thread& operator=(const rotation_thread&) = delete;
47 rotation_thread& operator=(rotation_thread&&) = delete;
0038180d 48 ~rotation_thread();
db66e574 49
0038180d
JG
50 /* Only use through the lttng_thread facilities. */
51 void launch_thread();
52 bool shutdown() const noexcept;
db66e574 53
0038180d
JG
54 /*
55 * Subscribe/unsubscribe the rotation_thread's notification_channel to/from
56 * session usage notifications to perform size-based rotations.
57 */
58 void subscribe_session_consumed_size_rotation(ltt_session& session, std::uint64_t size);
59 void unsubscribe_session_consumed_size_rotation(ltt_session& session);
60
61private:
62 void _thread_function() noexcept;
63 void _run();
64 void _handle_job_queue();
65 void _handle_notification(const lttng_notification& notification);
66 void _handle_notification_channel_activity();
67
68 struct rotation_thread_timer_queue& _rotation_timer_queue;
69 /* Access to the notification thread cmd_queue */
70 notification_thread_handle& _notification_thread_handle;
71 /* Thread-specific quit pipe. */
72 lttng_pipe::uptr _quit_pipe;
73 lttng_notification_channel::uptr _notification_channel;
74 /*
75 * Use an event_fd to wake-up the rotation thread whenever a command
76 * completes on the notification channel. This ensures that any
77 * notification that was queued while waiting for a reply to the command is
78 * eventually consumed.
79 */
80 lttng::eventfd _notification_channel_subscribtion_change_eventfd;
81 lttng_poll_event _events;
82};
83
84struct rotation_thread_timer_queue *rotation_thread_timer_queue_create(void);
85void rotation_thread_timer_queue_destroy(struct rotation_thread_timer_queue *queue);
92816cc3 86void rotation_thread_enqueue_job(struct rotation_thread_timer_queue *queue,
0038180d
JG
87 enum rotation_thread_job_type job_type,
88 struct ltt_session *session);
92816cc3 89
0038180d
JG
90} /* namespace sessiond */
91} /* namespace lttng */
db66e574
JD
92
93#endif /* ROTATION_THREAD_H */
This page took 0.083796 seconds and 4 git commands to generate.