33 #ifdef USE_STD_JTHREAD
56 #ifdef USE_STD_JTHREAD
57 stop_source_ = std::make_unique<stop_source_type>();
58 thread_ = std::make_unique<thread_type>([func = std::forward<F>(func),
this](std::stop_token st) {
63 thread_ = std::make_unique<thread_type>([func = std::forward<F>(func),
this]() {
73 #ifdef USE_STD_JTHREAD
75 stop_source_->request_stop();
88 #ifdef USE_STD_JTHREAD
89 return stop_source_ && stop_source_->stop_requested();
121 std::unique_ptr<thread_type>
thread_;
123 #ifdef USE_STD_JTHREAD
124 std::unique_ptr<stop_source_type> stop_source_;
Thread implementation abstraction that handles differences between std::jthread and std::thread.
void join()
Join the thread.
thread_impl(thread_impl &&)=default
bool stop_requested() const
Check if stop has been requested.
thread_impl(const thread_impl &)=delete
std::atomic< bool > stop_source_type
thread_impl & operator=(thread_impl &&)=default
thread_impl & operator=(const thread_impl &)=delete
std::unique_ptr< thread_type > thread_
bool joinable() const
Check if thread is joinable.
std::unique_ptr< stop_token_type > stop_requested_
std::atomic< bool > stop_token_type
void start_thread(F &&func)
Create and start a thread with the given function.
void detach()
Detach the thread.
void request_stop()
Request thread to stop.