24#include <kcenon/common/config/feature_flags.h>
26#include <condition_variable>
36#ifndef LOGGER_HAS_JTHREAD
37 #define LOGGER_HAS_JTHREAD KCENON_HAS_JTHREAD
56 stopped_.store(
true, std::memory_order_release);
63 return stopped_.load(std::memory_order_acquire);
70 stopped_.store(
false, std::memory_order_release);
100#if KCENON_HAS_JTHREAD
103 :
thread_(std::forward<F>(func)) {}
129#if KCENON_HAS_JTHREAD
130 :
thread_(std::move(other.thread_)) {}
133 ,
thread_(std::move(other.thread_)) {}
137 if (
this != &other) {
142#if KCENON_HAS_JTHREAD
143 thread_ = std::move(other.thread_);
146 thread_ = std::move(other.thread_);
156#if KCENON_HAS_JTHREAD
167#if KCENON_HAS_JTHREAD
180#if KCENON_HAS_JTHREAD
191#if !KCENON_HAS_JTHREAD
206#if KCENON_HAS_JTHREAD
232#if KCENON_HAS_JTHREAD
233 template<
typename Lock,
typename Predicate>
234 static bool wait(std::condition_variable_any& cv,
236 std::stop_token stop,
238 return cv.
wait(lock, stop, pred);
241 template<
typename Lock,
typename Predicate>
242 static bool wait(std::condition_variable& cv,
246 cv.wait(lock, [&]() {
Condition variable wait helper with stop support.
static bool wait(std::condition_variable &cv, Lock &lock, simple_stop_source &stop, Predicate pred)
Wait on condition variable with stop support.
Wrapper for std::jthread or std::thread with manual stop mechanism.
std::shared_ptr< simple_stop_source > get_stop_source() const noexcept
Get the stop source (fallback mode only)
compat_jthread & operator=(compat_jthread &&other) noexcept
compat_jthread(F &&func)
Construct and start thread with stop token support.
std::shared_ptr< simple_stop_source > stop_source_
~compat_jthread()
Destructor - requests stop and joins.
bool joinable() const noexcept
Check if thread is joinable.
compat_jthread(const compat_jthread &)=delete
void request_stop()
Request the thread to stop.
compat_jthread & operator=(const compat_jthread &)=delete
void join()
Wait for thread to complete.
compat_jthread() noexcept=default
Default constructor - no thread.
compat_jthread(compat_jthread &&other) noexcept
Simple stop source for environments without std::stop_token.
bool stop_requested() const noexcept
Check if stop was requested.
std::atomic< bool > stopped_
void reset()
Reset stop state (for reuse)
void request_stop()
Request stop.