31#include <condition_variable>
95 template <
typename Derived,
typename MessageDataType>
111 std::unique_lock<std::mutex> lock(*
_mtx);
122 catch (
const std::system_error& ex)
124 CBEAM_LOG(std::string{
"cbeam::concurrency::threaded_object::~threaded_object: "} + ex.what());
148 template <
typename... Args>
149 static std::unique_ptr<Derived>
create(std::shared_ptr<std::mutex> mtx, std::shared_ptr<std::condition_variable> cv, Args&&... args)
151 std::unique_ptr<Derived> obj = std::make_unique<Derived>(
construction_token{}, std::forward<Args>(args)...);
154 obj->_t = std::thread(&threaded_object::worker, obj.get());
161 class construction_token
164 construction_token() {}
189 std::shared_ptr<std::mutex>
_mtx;
190 std::shared_ptr<std::condition_variable>
_cv;
199 MessageDataType message_data;
202 std::unique_lock<std::mutex> lock(*
_mtx);
229 std::atomic<bool> _running{
true};
Definition threaded_object.hpp:162
std::shared_ptr< std::condition_variable > _cv
Definition threaded_object.hpp:190
virtual bool is_message_available()
Definition threaded_object.hpp:171
virtual void on_exit()
Definition threaded_object.hpp:185
std::shared_ptr< std::mutex > _mtx
Definition threaded_object.hpp:189
virtual ~threaded_object() noexcept
Destructor. Safely shuts down the managed thread by setting _running to false, notifying the conditio...
Definition threaded_object.hpp:108
static std::unique_ptr< Derived > create(std::shared_ptr< std::mutex > mtx, std::shared_ptr< std::condition_variable > cv, Args &&... args)
Definition threaded_object.hpp:149
virtual void on_start()
Definition threaded_object.hpp:167
threaded_object()=default
virtual MessageDataType get_message()
Definition threaded_object.hpp:176
virtual void on_message(const MessageDataType &) noexcept
Definition threaded_object.hpp:181
#define CBEAM_LOG(s)
Logs a message using cbeam::logging::log_manager.
Definition log_manager.hpp:124
Provides concurrency primitives and abstractions for multithreaded programming. It features the power...
Definition message_manager.hpp:47