2 * Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
9 #ifndef ROTATION_THREAD_H
10 #define ROTATION_THREAD_H
12 #include "notification-thread.hpp"
13 #include "session.hpp"
15 #include <common/compat/poll.hpp>
16 #include <common/eventfd.hpp>
17 #include <common/hashtable/hashtable.hpp>
18 #include <common/make-unique-wrapper.hpp>
19 #include <common/pipe.hpp>
21 #include <lttng/domain.h>
22 #include <lttng/notification/channel-internal.hpp>
26 #include <semaphore.h>
28 #include <urcu/list.h>
29 #include <urcu/rculfhash.h>
34 enum class rotation_thread_job_type { SCHEDULED_ROTATION, CHECK_PENDING_ROTATION };
36 struct rotation_thread_timer_queue;
38 class rotation_thread {
40 using uptr = std::unique_ptr<rotation_thread>;
42 rotation_thread(rotation_thread_timer_queue& rotation_timer_queue,
43 notification_thread_handle& notification_thread_handle);
46 /* Only use through the lttng_thread facilities. */
48 bool shutdown() const noexcept;
51 * Subscribe/unsubscribe the rotation_thread's notification_channel to/from
52 * session usage notifications to perform size-based rotations.
54 void subscribe_session_consumed_size_rotation(ltt_session& session, std::uint64_t size);
55 void unsubscribe_session_consumed_size_rotation(ltt_session& session);
58 void _thread_function() noexcept;
60 void _handle_job_queue();
61 void _handle_notification(const lttng_notification& notification);
62 void _handle_notification_channel_activity();
64 struct rotation_thread_timer_queue& _rotation_timer_queue;
65 /* Access to the notification thread cmd_queue */
66 notification_thread_handle& _notification_thread_handle;
67 /* Thread-specific quit pipe. */
68 lttng_pipe::uptr _quit_pipe;
69 lttng_notification_channel::uptr _notification_channel;
71 * Use an event_fd to wake-up the rotation thread whenever a command
72 * completes on the notification channel. This ensures that any
73 * notification that was queued while waiting for a reply to the command is
74 * eventually consumed.
76 lttng::eventfd _notification_channel_subscribtion_change_eventfd;
77 lttng_poll_event _events;
80 struct rotation_thread_timer_queue *rotation_thread_timer_queue_create(void);
81 void rotation_thread_timer_queue_destroy(struct rotation_thread_timer_queue *queue);
82 void rotation_thread_enqueue_job(struct rotation_thread_timer_queue *queue,
83 enum rotation_thread_job_type job_type,
84 struct ltt_session *session);
86 } /* namespace sessiond */
87 } /* namespace lttng */
89 #endif /* ROTATION_THREAD_H */