Cbeam
Loading...
Searching...
No Matches
cbeam::concurrency::threaded_object< Derived, MessageDataType > Class Template Reference

#include <threaded_object.hpp>

Classes

class  construction_token
 

Public Member Functions

 threaded_object ()=default
 
virtual ~threaded_object () noexcept
 Destructor. Safely shuts down the managed thread by setting _running to false, notifying the condition variable, and then joining the thread.Catches and logs any std::system_error thrown by thread::join. Asserts in debug mode if such an exception is caught, as it indicates a serious bug that must be addressed.
 

Static Public Member Functions

template<typename... Args>
static std::unique_ptr< Derived > create (std::shared_ptr< std::mutex > mtx, std::shared_ptr< std::condition_variable > cv, Args &&... args)
 

Protected Member Functions

virtual void on_start ()
 
virtual bool is_message_available ()
 
virtual MessageDataType get_message ()
 
virtual void on_message (const MessageDataType &) noexcept
 
virtual void on_exit ()
 

Protected Attributes

std::shared_ptr< std::mutex > _mtx
 
std::shared_ptr< std::condition_variable > _cv
 

Constructor & Destructor Documentation

◆ threaded_object()

template<typename Derived, typename MessageDataType>
cbeam::concurrency::threaded_object< Derived, MessageDataType >::threaded_object ( )
default

◆ ~threaded_object()

template<typename Derived, typename MessageDataType>
virtual cbeam::concurrency::threaded_object< Derived, MessageDataType >::~threaded_object ( )
inlinevirtualnoexcept

Destructor. Safely shuts down the managed thread by setting _running to false, notifying the condition variable, and then joining the thread.Catches and logs any std::system_error thrown by thread::join. Asserts in debug mode if such an exception is caught, as it indicates a serious bug that must be addressed.

Member Function Documentation

◆ create()

template<typename Derived, typename MessageDataType>
template<typename... Args>
static std::unique_ptr< Derived > cbeam::concurrency::threaded_object< Derived, MessageDataType >::create ( std::shared_ptr< std::mutex > mtx,
std::shared_ptr< std::condition_variable > cv,
Args &&... args )
inlinestatic

◆ get_message()

template<typename Derived, typename MessageDataType>
virtual MessageDataType cbeam::concurrency::threaded_object< Derived, MessageDataType >::get_message ( )
inlineprotectedvirtual

◆ is_message_available()

template<typename Derived, typename MessageDataType>
virtual bool cbeam::concurrency::threaded_object< Derived, MessageDataType >::is_message_available ( )
inlineprotectedvirtual

◆ on_exit()

template<typename Derived, typename MessageDataType>
virtual void cbeam::concurrency::threaded_object< Derived, MessageDataType >::on_exit ( )
inlineprotectedvirtual

Reimplemented in TestThreadedObject.

◆ on_message()

template<typename Derived, typename MessageDataType>
virtual void cbeam::concurrency::threaded_object< Derived, MessageDataType >::on_message ( const MessageDataType & )
inlineprotectedvirtualnoexcept

◆ on_start()

template<typename Derived, typename MessageDataType>
virtual void cbeam::concurrency::threaded_object< Derived, MessageDataType >::on_start ( )
inlineprotectedvirtual

Reimplemented in TestThreadedObject.

Member Data Documentation

◆ _cv

template<typename Derived, typename MessageDataType>
std::shared_ptr<std::condition_variable> cbeam::concurrency::threaded_object< Derived, MessageDataType >::_cv
protected

◆ _mtx

template<typename Derived, typename MessageDataType>
std::shared_ptr<std::mutex> cbeam::concurrency::threaded_object< Derived, MessageDataType >::_mtx
protected

The documentation for this class was generated from the following file: