X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Frotation-thread.hpp;h=02ff2b2fe1549baece8eb03563e5cf86fa39d658;hb=0038180de36c422cfaeade1145fa9fbc9436b8ad;hp=6dc7c97ac9a8b65142f3cf5a59c168ba8f0877ac;hpb=8b75cd779ffe332281fec189cdf808e4ee452572;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/rotation-thread.hpp b/src/bin/lttng-sessiond/rotation-thread.hpp index 6dc7c97ac..02ff2b2fe 100644 --- a/src/bin/lttng-sessiond/rotation-thread.hpp +++ b/src/bin/lttng-sessiond/rotation-thread.hpp @@ -9,44 +9,84 @@ #ifndef ROTATION_THREAD_H #define ROTATION_THREAD_H -#include -#include -#include -#include -#include +#include "notification-thread.hpp" +#include "session.hpp" + #include +#include #include +#include +#include + +#include +#include + +#include #include #include -#include "session.hpp" -#include "notification-thread.hpp" +#include +#include +#include -extern struct lttng_notification_channel *rotate_notification_channel; -extern int rotate_notification_channel_subscription_change_eventfd; +namespace lttng { +namespace sessiond { -enum rotation_thread_job_type { - ROTATION_THREAD_JOB_TYPE_SCHEDULED_ROTATION, - ROTATION_THREAD_JOB_TYPE_CHECK_PENDING_ROTATION +enum class rotation_thread_job_type { + SCHEDULED_ROTATION, + CHECK_PENDING_ROTATION }; struct rotation_thread_timer_queue; -struct rotation_thread_handle; -struct rotation_thread_timer_queue *rotation_thread_timer_queue_create(void); -void rotation_thread_timer_queue_destroy( - struct rotation_thread_timer_queue *queue); +class rotation_thread { +public: + using uptr = std::unique_ptr; -struct rotation_thread_handle *rotation_thread_handle_create( - struct rotation_thread_timer_queue *rotation_timer_queue, - struct notification_thread_handle *notification_thread_handle); + rotation_thread(rotation_thread_timer_queue& rotation_timer_queue, + notification_thread_handle& notification_thread_handle); + ~rotation_thread(); -void rotation_thread_handle_destroy( - struct rotation_thread_handle *handle); + /* Only use through the lttng_thread facilities. */ + void launch_thread(); + bool shutdown() const noexcept; + /* + * Subscribe/unsubscribe the rotation_thread's notification_channel to/from + * session usage notifications to perform size-based rotations. + */ + void subscribe_session_consumed_size_rotation(ltt_session& session, std::uint64_t size); + void unsubscribe_session_consumed_size_rotation(ltt_session& session); + +private: + void _thread_function() noexcept; + void _run(); + void _handle_job_queue(); + void _handle_notification(const lttng_notification& notification); + void _handle_notification_channel_activity(); + + struct rotation_thread_timer_queue& _rotation_timer_queue; + /* Access to the notification thread cmd_queue */ + notification_thread_handle& _notification_thread_handle; + /* Thread-specific quit pipe. */ + lttng_pipe::uptr _quit_pipe; + lttng_notification_channel::uptr _notification_channel; + /* + * Use an event_fd to wake-up the rotation thread whenever a command + * completes on the notification channel. This ensures that any + * notification that was queued while waiting for a reply to the command is + * eventually consumed. + */ + lttng::eventfd _notification_channel_subscribtion_change_eventfd; + lttng_poll_event _events; +}; + +struct rotation_thread_timer_queue *rotation_thread_timer_queue_create(void); +void rotation_thread_timer_queue_destroy(struct rotation_thread_timer_queue *queue); void rotation_thread_enqueue_job(struct rotation_thread_timer_queue *queue, - enum rotation_thread_job_type job_type, - struct ltt_session *session); + enum rotation_thread_job_type job_type, + struct ltt_session *session); -bool launch_rotation_thread(struct rotation_thread_handle *handle); +} /* namespace sessiond */ +} /* namespace lttng */ #endif /* ROTATION_THREAD_H */