Core Library  1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
core_lib::threads::EventThread Class Referencefinal

Class defining an EventThread that ticks at a given rate and executes a registered callback. More...

#include <EventThread.h>

Inheritance diagram for core_lib::threads::EventThread:
core_lib::threads::ThreadBase

Public Member Functions

 EventThread (event_callback_t const &eventCallback, unsigned int eventPeriodMillisecs, bool delayedStart=false)
 EventThread constructor. More...
 
 ~EventThread () override
 EventThread destructor.
 
 EventThread (const EventThread &)=delete
 Copy constructor deleted.
 
EventThreadoperator= (const EventThread &)=delete
 Copy assignment operator deleted.
 
 EventThread (EventThread &&)=delete
 Move constructor deleted.
 
EventThreadoperator= (EventThread &&)=delete
 Move assignment operator deleted.
 
void EventPeriod (unsigned int eventPeriodMillisecs)
 Set even thread's tick period. More...
 
unsigned int EventPeriod () const
 Set even threads tick period. More...
 
void ForceTick ()
 Forces the thread to tick.
 
- Public Member Functions inherited from core_lib::threads::ThreadBase
 ThreadBase (const ThreadBase &)=delete
 Copy constructor deleted.
 
ThreadBaseoperator= (const ThreadBase &)=delete
 Copy assignment operator deleted.
 
 ThreadBase (ThreadBase &&)=default
 Move constructor deleted.
 
ThreadBaseoperator= (ThreadBase &&)=default
 Move assignment operator deleted.
 
virtual ~ThreadBase ()=default
 Destructor.
 
bool IsStarted () const
 Is thread started. More...
 
bool Start ()
 Start the thread. More...
 
bool Stop ()
 Safely stop the thread. More...
 
std::thread::id ThreadID () const
 Get this thread's thread ID. More...
 
std::thread::native_handle_type NativeHandle () const
 Get the underlying std::thread's native handle. More...
 

Private Types

using event_callback_t = std::function< void()>
 Typedef defining message handler functor.
 

Private Member Functions

void ThreadIteration () NO_EXCEPT_ override
 Thread iteration function.
 
void ProcessTerminationConditions () NO_EXCEPT_ override
 Function to process termination conditions.
 

Private Attributes

std::mutex m_eventTickMutex
 Update event.
 
core_lib::threads::SyncEvent m_updateEvent {}
 Update event.
 
event_callback_t m_eventCallback {}
 Callback fires on event.
 
unsigned int m_eventPeriodMillisecs {0}
 Event tick period.
 

Additional Inherited Members

- Protected Member Functions inherited from core_lib::threads::ThreadBase
 ThreadBase ()=default
 Default constructor.
 
void SetTerminating (bool terminating=true)
 Set terminating flag. More...
 
bool IsTerminating () const
 Is thread terminating. More...
 
void SleepForTime (unsigned int milliSecs) const
 Make this thread sleep for a period of time. More...
 

Detailed Description

Class defining an EventThread that ticks at a given rate and executes a registered callback.

Constructor & Destructor Documentation

◆ EventThread()

core_lib::threads::EventThread::EventThread ( event_callback_t const &  eventCallback,
unsigned int  eventPeriodMillisecs,
bool  delayedStart = false 
)

EventThread constructor.

Parameters
[in]eventCallback- Function object to be called when event ticks.
[in]eventPeriodMillisecs- Period between signalling of the event.
[in]delayedStart- (Optional) Delay startiong of the thread.

If delayedStart == true then user must call EventThread::Start() themselves.

Member Function Documentation

◆ EventPeriod() [1/2]

void core_lib::threads::EventThread::EventPeriod ( unsigned int  eventPeriodMillisecs)

Set even thread's tick period.

Parameters
[in]eventPeriodMillisecs- Period between signalling of the event.

◆ EventPeriod() [2/2]

unsigned int core_lib::threads::EventThread::EventPeriod ( ) const

Set even threads tick period.

Returns
Event tick.

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