DynExp
Highly flexible laboratory automation for dynamically changing experiments.
DynExp::RunnableObject Class Referenceabstract

Defines an Object which possesses a thread it runs in. The RunnableObject can be started and stopped as well as paused and resumed. More...

+ Inheritance diagram for DynExp::RunnableObject:

Classes

class  NotUnusedException
 Exception type thrown by TerminateImpl() if the RunnableObject cannot be terminated for being used by another Object instance. More...
 
class  RunnableInstanceOnlyType
 Allow exclusive access to some of RunnableObject's private methods to class RunnableInstance. More...
 

Public Types

using ParamsType = RunnableObjectParams
 Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object. More...
 
using ConfigType = RunnableObjectConfigurator
 Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object. More...
 
- Public Types inherited from DynExp::Object
using ParamsType = ParamsBase
 Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object. More...
 
using ParamsTypeSyncPtrType = Util::SynchronizedPointer< ParamsType >
 Alias for the return type of Object::GetParams(). Parameters wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way. More...
 
using ParamsConstTypeSyncPtrType = Util::SynchronizedPointer< const ParamsType >
 Alias for the return type of Object::GetParams() const. Parameters wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way. More...
 
using ConfigType = ConfiguratorBase
 Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object. More...
 
using ParamsGetterType = Util::CallableMemberWrapper< Object, decltype(&Object::GetParams)>
 Invoking an instance of this alias is supposed to call Object::GetParams() of the instance the Util::CallableMemberWrapper has been constructed with. More...
 

Public Member Functions

 RunnableObject (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
 Constructs an Object instance. More...
 
virtual ~RunnableObject ()=0
 
void SetPaused (bool Pause, std::string Description="")
 Pauses or resumes a RunnableObject instance. Its thread stays running, but the instance does not perform any action while it is paused. More...
 
bool IsRunning () const noexcept
 Returns Running. More...
 
bool IsPaused () const noexcept
 Returns Paused. More...
 
bool IsExiting () const noexcept
 Returns ShouldExit. More...
 
auto GetStartupType () const noexcept
 Returns Startup. More...
 
auto GetReasonWhyPaused () const
 Returns ReasonWhyPaused. More...
 
Not thread-safe

These functions must be called by the thread owning this Object instance only!

bool Run (QWidget *ParentWidget=nullptr)
 Starts the RunnableObject instance's thread and ensures that all Object instances linked to this instance via ObjectLink parameters are in a ready state. Calls RunChild() which is to be overridden by derived classes to start a thread and to pass this thread back by calling StoreThread(). More...
 
bool RunIfRunAutomatic ()
 Calls Run() if RunnableObjectParams::Startup is set to RunnableObjectParams::Automatic. More...
 
bool RunIfRunOnCreation ()
 Calls Run() if RunnableObjectParams::Startup is set to RunnableObjectParams::OnCreation. More...
 
void Terminate (bool Force=false, const std::chrono::milliseconds Timeout=TerminateTimeoutDefault)
 Notifies the RunnableObject instance's thread to terminate and waits until it has ended. Calls TerminateImpl(). More...
 
- Public Member Functions inherited from Util::INonCopyable
 INonCopyable (const INonCopyable &)=delete
 
INonCopyableoperator= (const INonCopyable &)=delete
 
- Public Member Functions inherited from DynExp::Object
ItemIDType GetID () const noexcept
 Returns the ID of this Object instance. Thread-safe since ID is const. More...
 
std::string GetCategoryAndName () const
 Builds a string from an Object's category and name to allow the user to identify an Object's type. More...
 
void EnsureReadyState (bool IsAutomaticStartup)
 Ensures that this Object instance is ready by possibly starting its worker thread or by opening connections to hardware devices. More...
 
void CheckLinkedObjectStates () const
 Checks whether Object instances this instance uses are in a ready state. Override CheckLinkedObjectStatesChild() to implement this behavior. More...
 
void Reset ()
 Resets this Object instance (including all its derived classes) by calling ResetImpl(). A reset implies that the derived classes reload all their parameters from Params and that all LinkedObjectWrapper instances owned by this Object instance become invalidated. More...
 
void BlockIfUnused (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout)
 Blocks this Object instance setting Object::IsBlocked to true. Refer to Object::IsBlocked for the consequences. More...
 
ParamsConstTypeSyncPtrType GetParams (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Locks the mutex of the parameter class instance Params assigned to this Object instance and returns a pointer to the locked Params. More...
 
ParamsTypeSyncPtrType GetParams (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault)
 Locks the mutex of the parameter class instance Params assigned to this Object instance and returns a pointer to the locked Params. More...
 
auto GetObjectName (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Returns the name of this Object instance. More...
 
bool IsSharedUsageEnabled (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Returns whether shared usage has been enabled for this Object instance. Refer to ParamsBase::UsageType. More...
 
void SetWarning (std::string Description, int ErrorCode) const
 Setter for Object::Warning. Sets the warning by a description and an error code. More...
 
void SetWarning (const Util::Exception &e) const
 Setter for Object::Warning. Sets the warning by retrieving the warning data from an exception e. More...
 
void ClearWarning () const
 Resets Object::Warning. More...
 
auto GetWarning () const
 Returns Object::Warning in a thread-safe way by copying its internal data. More...
 
std::exception_ptr GetException (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Returns a pointer to the exception which has caused this Object instance to fail. More...
 
bool IsReady () const
 Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) and not blocked (refer to Object::IsBlocked). More...
 
auto GetUseCount (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Counts the registered useres in a thread-safe way. More...
 
bool IsUnused (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Returns whether this Object instance is used by other instances. More...
 
auto GetUserIDs (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Returns a list of the IDs of the registered users in a thread-safe way. More...
 
auto GetUserNamesString (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Builds a string describing which users are registered containing their object names, categories and type names in a thread-safe way. More...
 
virtual std::string GetName () const =0
 Returns the name of this Object type. More...
 
virtual std::string GetCategory () const =0
 Returns the category of this Object type. More...
 

Public Attributes

RunnableInstanceOnlyType RunnableInstanceOnly
 Allow exclusive access to some of RunnableObject's private methods to class RunnableInstance. More...
 
- Public Attributes inherited from DynExp::Object
LinkedObjectWrapperOnlyType LinkedObjectWrapperOnly
 Allow exclusive access to some of Object's private methods to any LinkedObjectWrapper<T>. More...
 

Static Public Attributes

static constexpr auto ShortTimeoutDefault = std::chrono::milliseconds(50)
 Default timeout e.g. used as a default for calls to InstrumentBase::GetInstrumentData or ModuleBase::GetModuleData. More...
 
static constexpr auto TerminateTimeoutDefault = std::chrono::milliseconds(3000)
 Default timeout used as a default for calls to RunnableObject::Terminate. More...
 
- Static Public Attributes inherited from DynExp::Object
static constexpr std::chrono::milliseconds GetParamsTimeoutDefault = std::chrono::milliseconds(100)
 Default timeout used by Object::GetParams() to lock the mutex of the parameter instance assigned to this Object instance. More...
 

Protected Member Functions

void Init ()
 Initializes member variables in case of a reset. More...
 
std::promise< void > MakeThreadExitedPromise ()
 Helper function to be used by overridden RunChild() functions in derived classes to (re)initialize the ThreadExitedSignal future and to provide the derived class a promise to signal the RunnableObject instance that its thread has terminated. More...
 
void StoreThread (std::thread &&Thread) noexcept
 Stores a thread constructed by a derived class overriding RunChild() in Thread taking ownership of the thread. Only call this function within RunChild()! More...
 
bool IsCallFromRunnableThread () const
 Checks whether Thread's id matches the id of the calling thread. This is thread-safe if the function is called by the RunnableObject instance's thread since Terminate() joins the threads before changing the Thread member. It is also thread-safe if the function is called by the thread owning the the RunnableObject instance since Run() and Terminate() can only be called by this thread. Only Run() and Terminate() (indirectly) modify Thread. More...
 
void EnsureCallFromRunnableThread () const
 Asserts that the call to this function is performed from the RunnableObject instance's thread by calling IsCallFromRunnableThread(). More...
 
void SetReasonWhyPaused (std::string Description)
 Sets the reason why this RunnableObject instance has been paused. More...
 
void SetReasonWhyPaused (const Util::Exception &e)
 Sets the reason why this RunnableObject instance has been paused. More...
 
void ClearReasonWhyPaused ()
 Removes the reason why this RunnableObject instance has been paused (since it is resumed). More...
 
- Protected Member Functions inherited from Util::INonCopyable
constexpr INonCopyable ()=default
 
 ~INonCopyable ()=default
 
- Protected Member Functions inherited from DynExp::Object
 Object (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
 Constructs an Object instance. More...
 
virtual ~Object ()=0
 
void EnsureCallFromOwningThread () const
 Asserts that the call to this function is performed from the thread which constructed this Object instance (the thread with the id stored in Object::OwnerThreadID). More...
 
ParamsTypeSyncPtrType GetNonConstParams (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Allows derived Objects to edit their own parameters - even in const task functions (for instruments) or event functions (for modules). More...
 
auto LockUserList (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout)
 Locks the user list for thread-safe manipulation. More...
 
void DeregisterAllUnsafe ()
 Deregisters all users and notifies them that they need to check the states of their used linked objects. More...
 
auto GetUseCountUnsafe ()
 
auto GetUserNamesStringUnsafe () const
 
bool IsUnusedUnsafe ()
 Returns whether this Object instance is used by other instances (not thread-safe). More...
 

Private Member Functions

void ResetImpl (dispatch_tag< Object >) override final
 Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy. More...
 
virtual void ResetImpl (dispatch_tag< RunnableObject >)=0
 Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy. More...
 
void EnsureReadyStateChild (bool IsAutomaticStartup) override final
 Ensures that this Object instance is ready by possibly starting its worker thread or by opening connections to hardware devices. More...
 
void CheckLinkedObjectStatesChild () const override final
 Override to implement a check whether linked objects are in a ready state. More...
 
void TerminateImpl (bool Force, const std::chrono::milliseconds Timeout=TerminateTimeoutDefault)
 Notifies the RunnableObject instance's thread to terminate and waits until it has ended. Calls TerminateImpl(). More...
 
void TerminateUnsafe (bool Force, const std::chrono::milliseconds Timeout=TerminateTimeoutDefault)
 Notifies the RunnableObject instance's thread to terminate and waits until it has ended. Calls TerminateImpl(). More...
 
void OnThreadHasExited () noexcept
 This function is called when the RunnableObject instance's thread terminates. The thread receives a RunnableInstance instance as a parameter. When it exits, this RunnableInstance instance is destroyed. So, RunnableInstance's destructor is invoked. It calls RunnableInstance::SetThreadExited(), which in turn calls this function, and signals the thread termination to ThreadExitedSignal. More...
 
Override

Override by derived classes.

virtual void RunChild ()=0
 Refer to Run(). More...
 
virtual void NotifyChild ()
 Notify derived classes that some state has changed (e.g. the termination of Thread is requested) and that the child's event/task queue should run now. More...
 
virtual void TerminateChild (const std::chrono::milliseconds Timeout)
 Signals derived classes that terminating the RunnableObject instance's thread is about to be requested. Derived classes might now enqueue respective exit tasks/events into their task/event queues. Refer to TerminateUnsafe(). More...
 
virtual std::unique_ptr< BusyDialogMakeStartupBusyDialogChild (QWidget *ParentWidget) const
 Override to make this function return a pointer to a BusyDialog instance. Refer to Run(). More...
 

Private Attributes

std::atomic< RunnableObjectParams::StartupTypeStartup = RunnableObjectParams::StartupType::Automatic
 Reflects the value of RunnableObjectParams::Startup. This variable is only updated when Run() is called. It is atomic to allow the UI thread reading it safely. More...
 
std::thread Thread
 The RunnableObject instance's thread. More...
 
std::future< void > ThreadExitedSignal
 Future which signals that Thread has terminated. Refer to OnThreadHasExited(). More...
 
std::atomic< bool > Running
 Indicates whether the RunnableObject instance is running. More...
 
std::atomic< bool > Paused
 Indicates whether the RunnableObject instance is paused. More...
 
Util::Warning ReasonWhyPaused
 Holds information about why the RunnableObject instance is paused. More...
 
std::atomic< bool > LinkedObjStateCheckRequested = false
 Indicates whether the RunnableInstance instance belonging to this RunnableObject instance's thread should recheck the states of all Object instances this RunnableObject uses. More...
 
Inter-thread communication

These variables are for communication from the thread owning this RunnableObject instance to its thread Thread only.

std::atomic< bool > ShouldExit
 Indicates whether this RunnableObject instance's thread should terminate. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from DynExp::Object
static std::string CategoryAndNameToStr (const std::string &Category, const std::string &Name)
 Builds a string from an Object's category and name to allow the user to identify an Object's type. More...
 

Detailed Description

Defines an Object which possesses a thread it runs in. The RunnableObject can be started and stopped as well as paused and resumed.

Definition at line 2425 of file Object.h.

Member Typedef Documentation

◆ ConfigType

Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object.

Definition at line 2483 of file Object.h.

◆ ParamsType

Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object.

Definition at line 2482 of file Object.h.

Constructor & Destructor Documentation

◆ RunnableObject()

DynExp::RunnableObject::RunnableObject ( const std::thread::id  OwnerThreadID,
ParamsBasePtrType &&  Params 
)

Constructs an Object instance.

Parameters
OwnerThreadIDThread id of the thread owning the Object instance to be constructed.
ParamsParameter class instance to be assigned to the Object instance to be constructed.
Exceptions
Util::InvalidArgExceptionis thrown if OwnerThreadID is an invalid thread id or if Params is nullptr.

Definition at line 518 of file Object.cpp.

◆ ~RunnableObject()

DynExp::RunnableObject::~RunnableObject ( )
pure virtual

Definition at line 524 of file Object.cpp.

Member Function Documentation

◆ CheckLinkedObjectStatesChild()

void DynExp::RunnableObject::CheckLinkedObjectStatesChild ( ) const
inlinefinaloverrideprivatevirtual

Override to implement a check whether linked objects are in a ready state.

Reimplemented from DynExp::Object.

Definition at line 2617 of file Object.h.

◆ ClearReasonWhyPaused()

void DynExp::RunnableObject::ClearReasonWhyPaused ( )
inlineprotected

Removes the reason why this RunnableObject instance has been paused (since it is resumed).

Definition at line 2610 of file Object.h.

◆ EnsureCallFromRunnableThread()

void DynExp::RunnableObject::EnsureCallFromRunnableThread ( ) const
protected

Asserts that the call to this function is performed from the RunnableObject instance's thread by calling IsCallFromRunnableThread().

Exceptions
Util::InvalidCallExceptionis thrown if the assertion fails.

Definition at line 661 of file Object.cpp.

◆ EnsureReadyStateChild()

void DynExp::RunnableObject::EnsureReadyStateChild ( bool  IsAutomaticStartup)
finaloverrideprivatevirtual

Ensures that this Object instance is ready by possibly starting its worker thread or by opening connections to hardware devices.

Parameters
IsAutomaticStartupPass true if ensuring other Object instances to be ready have caused a call to this function. Pass false if an action performed by the user has caused the call to this function.

Implements DynExp::Object.

Definition at line 676 of file Object.cpp.

◆ GetReasonWhyPaused()

auto DynExp::RunnableObject::GetReasonWhyPaused ( ) const
inline

Returns ReasonWhyPaused.

Definition at line 2555 of file Object.h.

◆ GetStartupType()

auto DynExp::RunnableObject::GetStartupType ( ) const
inlinenoexcept

Returns Startup.

Definition at line 2554 of file Object.h.

◆ Init()

void DynExp::RunnableObject::Init ( )
protected

Initializes member variables in case of a reset.

Definition at line 634 of file Object.cpp.

◆ IsCallFromRunnableThread()

bool DynExp::RunnableObject::IsCallFromRunnableThread ( ) const
protected

Checks whether Thread's id matches the id of the calling thread. This is thread-safe if the function is called by the RunnableObject instance's thread since Terminate() joins the threads before changing the Thread member. It is also thread-safe if the function is called by the thread owning the the RunnableObject instance since Run() and Terminate() can only be called by this thread. Only Run() and Terminate() (indirectly) modify Thread.

Returns
Returns true of both ids match, false otherwise.

Definition at line 656 of file Object.cpp.

◆ IsExiting()

bool DynExp::RunnableObject::IsExiting ( ) const
inlinenoexcept

Returns ShouldExit.

Definition at line 2552 of file Object.h.

◆ IsPaused()

bool DynExp::RunnableObject::IsPaused ( ) const
inlinenoexcept

Returns Paused.

Definition at line 2551 of file Object.h.

◆ IsRunning()

bool DynExp::RunnableObject::IsRunning ( ) const
inlinenoexcept

Returns Running.

Definition at line 2550 of file Object.h.

◆ MakeStartupBusyDialogChild()

virtual std::unique_ptr<BusyDialog> DynExp::RunnableObject::MakeStartupBusyDialogChild ( QWidget *  ParentWidget) const
inlineprivatevirtual

Override to make this function return a pointer to a BusyDialog instance. Refer to Run().

Parameters
ParentWidgetQt QWidget acting as a parent of the modal busy dialog
Returns
Pointer to a BusyDialog instance

Reimplemented in DynExp::ModuleBase.

Definition at line 2646 of file Object.h.

◆ MakeThreadExitedPromise()

std::promise< void > DynExp::RunnableObject::MakeThreadExitedPromise ( )
protected

Helper function to be used by overridden RunChild() functions in derived classes to (re)initialize the ThreadExitedSignal future and to provide the derived class a promise to signal the RunnableObject instance that its thread has terminated.

Returns
Promise bound to the ThreadExitedSignal future

Definition at line 643 of file Object.cpp.

◆ NotifyChild()

virtual void DynExp::RunnableObject::NotifyChild ( )
inlineprivatevirtual

Notify derived classes that some state has changed (e.g. the termination of Thread is requested) and that the child's event/task queue should run now.

Reimplemented in DynExp::ModuleBase, and DynExp::InstrumentBase.

Definition at line 2629 of file Object.h.

◆ OnThreadHasExited()

void DynExp::RunnableObject::OnThreadHasExited ( )
privatenoexcept

This function is called when the RunnableObject instance's thread terminates. The thread receives a RunnableInstance instance as a parameter. When it exits, this RunnableInstance instance is destroyed. So, RunnableInstance's destructor is invoked. It calls RunnableInstance::SetThreadExited(), which in turn calls this function, and signals the thread termination to ThreadExitedSignal.

Definition at line 713 of file Object.cpp.

◆ ResetImpl() [1/2]

void DynExp::RunnableObject::ResetImpl ( dispatch_tag< Object )
finaloverrideprivatevirtual

Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy.

Implements DynExp::Object.

Definition at line 668 of file Object.cpp.

◆ ResetImpl() [2/2]

virtual void DynExp::RunnableObject::ResetImpl ( dispatch_tag< RunnableObject )
privatepure virtual

Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy.

Implemented in DynExp::ModuleBase, and DynExp::InstrumentBase.

◆ Run()

bool DynExp::RunnableObject::Run ( QWidget *  ParentWidget = nullptr)

Starts the RunnableObject instance's thread and ensures that all Object instances linked to this instance via ObjectLink parameters are in a ready state. Calls RunChild() which is to be overridden by derived classes to start a thread and to pass this thread back by calling StoreThread().

Parameters
ParentWidgetQt QWidget acting as a parent of the modal busy dialog (BusyDialog) to be displayed while starting the linked Object instances.
Returns
Returns true if the RunnableObject instance has been started now, false otherwise (e.g. if it is already running or if the startup policy (RunnableObjectParams::Startup) prohibits so).
Exceptions
Util::InvalidStateExceptionis thrown if the RunnableObject instance is in an error state. Call Object::Reset() to resolve this.

Definition at line 550 of file Object.cpp.

◆ RunChild()

virtual void DynExp::RunnableObject::RunChild ( )
privatepure virtual

Refer to Run().

Implemented in DynExp::ModuleBase, and DynExp::InstrumentBase.

◆ RunIfRunAutomatic()

bool DynExp::RunnableObject::RunIfRunAutomatic ( )

Calls Run() if RunnableObjectParams::Startup is set to RunnableObjectParams::Automatic.

Returns
Returns true if the RunnableObject instance has been started now, false otherwise (e.g. if it is already running or if the startup policy (RunnableObjectParams::Startup) prohibits so).
Exceptions
Util::NotAvailableExceptionis thrown if the RunnableObject instance is not already running and if RunnableObjectParams::Startup is not set to RunnableObjectParams::Automatic.

Definition at line 594 of file Object.cpp.

◆ RunIfRunOnCreation()

bool DynExp::RunnableObject::RunIfRunOnCreation ( )

Calls Run() if RunnableObjectParams::Startup is set to RunnableObjectParams::OnCreation.

Returns
Returns true if the RunnableObject instance has been started now, false otherwise (e.g. if it is already running or if the startup policy (RunnableObjectParams::Startup) prohibits so).

Definition at line 607 of file Object.cpp.

◆ SetPaused()

void DynExp::RunnableObject::SetPaused ( bool  Pause,
std::string  Description = "" 
)

Pauses or resumes a RunnableObject instance. Its thread stays running, but the instance does not perform any action while it is paused.

Parameters
PausePass true to pause the RunnableObject instance or false to resume it. If Pause is false, ClearReasonWhyPaused() is called.
DescriptionIf Pause is true, Description is passed to SetReasonWhyPaused().

Definition at line 624 of file Object.cpp.

◆ SetReasonWhyPaused() [1/2]

void DynExp::RunnableObject::SetReasonWhyPaused ( const Util::Exception e)
inlineprotected

Sets the reason why this RunnableObject instance has been paused.

Parameters
eException containing the reason (including a human-readable description)

Definition at line 2605 of file Object.h.

◆ SetReasonWhyPaused() [2/2]

void DynExp::RunnableObject::SetReasonWhyPaused ( std::string  Description)
inlineprotected

Sets the reason why this RunnableObject instance has been paused.

Parameters
DescriptionHuman-readable string describing the reason

Definition at line 2599 of file Object.h.

◆ StoreThread()

void DynExp::RunnableObject::StoreThread ( std::thread &&  Thread)
protectednoexcept

Stores a thread constructed by a derived class overriding RunChild() in Thread taking ownership of the thread. Only call this function within RunChild()!

Parameters
ThreadThread to store.

Definition at line 651 of file Object.cpp.

◆ Terminate()

void DynExp::RunnableObject::Terminate ( bool  Force = false,
const std::chrono::milliseconds  Timeout = TerminateTimeoutDefault 
)

Notifies the RunnableObject instance's thread to terminate and waits until it has ended. Calls TerminateImpl().

Parameters
ForceIf true, the RunnableObject is terminated even if it is still used.
TimeoutTime to wait until the RunnableObject's thread has ended.

Definition at line 617 of file Object.cpp.

◆ TerminateChild()

virtual void DynExp::RunnableObject::TerminateChild ( const std::chrono::milliseconds  Timeout)
inlineprivatevirtual

Signals derived classes that terminating the RunnableObject instance's thread is about to be requested. Derived classes might now enqueue respective exit tasks/events into their task/event queues. Refer to TerminateUnsafe().

Parameters
TimeoutTime to wait until the RunnableObject's thread has ended.

Reimplemented in DynExp::ModuleBase, and DynExp::InstrumentBase.

Definition at line 2638 of file Object.h.

◆ TerminateImpl()

void DynExp::RunnableObject::TerminateImpl ( bool  Force,
const std::chrono::milliseconds  Timeout = TerminateTimeoutDefault 
)
private

Notifies the RunnableObject instance's thread to terminate and waits until it has ended. Calls TerminateImpl().

Parameters
ForceIf true, the RunnableObject is terminated even if it is still used.
TimeoutTime to wait until the RunnableObject's thread has ended.

Bypasses the assertion check provided by Object::EnsureCallFromOwningThread(). Ensures thread-safety and calls TerminateUnsafe().

Exceptions
NotUnusedExceptionis thrown in case Force is false and if this RunnableObject instance is used by other Object instances.

Definition at line 681 of file Object.cpp.

◆ TerminateUnsafe()

void DynExp::RunnableObject::TerminateUnsafe ( bool  Force,
const std::chrono::milliseconds  Timeout = TerminateTimeoutDefault 
)
private

Notifies the RunnableObject instance's thread to terminate and waits until it has ended. Calls TerminateImpl().

Parameters
ForceIf true, the RunnableObject is terminated even if it is still used.
TimeoutTime to wait until the RunnableObject's thread has ended.

Joins this RunnableObject instance's thread. Does nothing if Thread is not joinable. Not thread-safe. Called by TerminateImpl(). Calls TerminateChild() before any other action.

Exceptions
Util::ThreadDidNotRespondExceptionis thrown if the thread does not terminate within the TerminateTimeoutDefault timeout after setting ShouldExit to true and calling NotifyChild().

Definition at line 695 of file Object.cpp.

Member Data Documentation

◆ LinkedObjStateCheckRequested

std::atomic<bool> DynExp::RunnableObject::LinkedObjStateCheckRequested = false
mutableprivate

Indicates whether the RunnableInstance instance belonging to this RunnableObject instance's thread should recheck the states of all Object instances this RunnableObject uses.

Definition at line 2700 of file Object.h.

◆ Paused

std::atomic<bool> DynExp::RunnableObject::Paused
private

Indicates whether the RunnableObject instance is paused.

Definition at line 2685 of file Object.h.

◆ ReasonWhyPaused

Util::Warning DynExp::RunnableObject::ReasonWhyPaused
private

Holds information about why the RunnableObject instance is paused.

Definition at line 2686 of file Object.h.

◆ RunnableInstanceOnly

RunnableInstanceOnlyType DynExp::RunnableObject::RunnableInstanceOnly

Allow exclusive access to some of RunnableObject's private methods to class RunnableInstance.

Definition at line 2557 of file Object.h.

◆ Running

std::atomic<bool> DynExp::RunnableObject::Running
private

Indicates whether the RunnableObject instance is running.

Definition at line 2684 of file Object.h.

◆ ShortTimeoutDefault

constexpr auto DynExp::RunnableObject::ShortTimeoutDefault = std::chrono::milliseconds(50)
staticconstexpr

Default timeout e.g. used as a default for calls to InstrumentBase::GetInstrumentData or ModuleBase::GetModuleData.

Definition at line 2489 of file Object.h.

◆ ShouldExit

std::atomic<bool> DynExp::RunnableObject::ShouldExit
private

Indicates whether this RunnableObject instance's thread should terminate.

Definition at line 2693 of file Object.h.

◆ Startup

std::atomic<RunnableObjectParams::StartupType> DynExp::RunnableObject::Startup = RunnableObjectParams::StartupType::Automatic
private

Reflects the value of RunnableObjectParams::Startup. This variable is only updated when Run() is called. It is atomic to allow the UI thread reading it safely.

Definition at line 2680 of file Object.h.

◆ TerminateTimeoutDefault

constexpr auto DynExp::RunnableObject::TerminateTimeoutDefault = std::chrono::milliseconds(3000)
staticconstexpr

Default timeout used as a default for calls to RunnableObject::Terminate.

Definition at line 2494 of file Object.h.

◆ Thread

std::thread DynExp::RunnableObject::Thread
private

The RunnableObject instance's thread.

Definition at line 2682 of file Object.h.

◆ ThreadExitedSignal

std::future<void> DynExp::RunnableObject::ThreadExitedSignal
private

Future which signals that Thread has terminated. Refer to OnThreadHasExited().

Definition at line 2683 of file Object.h.


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