12 , stop_source_(
std::nullopt)
14 , stop_requested_(false)
21 return state_.load(std::memory_order_acquire);
26 state_.store(state, std::memory_order_release);
31 auto condition =
state_.load(std::memory_order_acquire);
44 stop_source_ = std::stop_source();
46 stop_requested_.store(
false, std::memory_order_release);
54 if (stop_source_.has_value())
56 stop_source_.value().request_stop();
66 if (stop_source_.has_value())
68 return stop_source_.value().stop_requested();
79 return stop_source_.has_value();
82 auto state =
state_.load(std::memory_order_acquire);
97 return std::unique_lock<std::mutex>(cv_mutex_);
102 std::scoped_lock<std::mutex> lock(cv_mutex_);
103 condition_.notify_one();
108 std::scoped_lock<std::mutex> lock(cv_mutex_);
109 condition_.notify_all();
auto is_stop_requested() const noexcept -> bool
Checks if a stop has been requested.
auto set_state(thread_conditions state) noexcept -> void
Sets the thread condition/state.
auto notify_all() -> void
Notifies all waiting threads.
auto request_stop() noexcept -> void
Requests the thread to stop.
auto has_active_source() const noexcept -> bool
Checks if the controller has an active stop source (C++20 only).
auto notify_one() -> void
Notifies one waiting thread.
auto initialize_for_start() -> void
Initializes the controller for a new thread start.
auto set_stopped() noexcept -> void
Marks the thread as stopped.
std::atomic< bool > stop_requested_
Atomic flag for stop request (legacy mode).
auto acquire_lock() -> std::unique_lock< std::mutex >
Acquires a unique lock on the condition variable mutex.
auto is_running() const noexcept -> bool
Checks if the thread is currently running.
lifecycle_controller()
Constructs a new lifecycle_controller in Created state.
auto reset_stop_source() noexcept -> void
Resets the stop control mechanism after thread completion.
std::atomic< thread_conditions > state_
Current thread state.
auto get_state() const noexcept -> thread_conditions
Gets the current thread condition/state.
Centralized thread lifecycle state and synchronization management.
Core threading foundation of the thread system library.
thread_conditions
Enumeration of various states in a thread's lifecycle.
@ Created
Thread created but not started.
@ Waiting
Thread waiting for work or tasks.
@ Working
Thread currently processing a task.
@ Stopped
Thread fully stopped.