Flair
Framework Libre Air
flair::core::Thread Class Referenceabstract

Abstract class for a thread. More...

#include <Thread.h>

+ Inheritance diagram for flair::core::Thread:

Public Member Functions

 Thread (const Object *parent, std::string name, uint8_t priority, uint32_t stackSize=1024 *128)
 Constructor. More...
 
virtual ~Thread ()
 Destructor. More...
 
void Start (void)
 Start the thread. More...
 
void SafeStop (void)
 Set a stop flag. More...
 
bool ToBeStopped (void) const
 Set a stop flag. More...
 
void Join (void)
 Join the thread. More...
 
void SetPeriodUS (uint32_t period_us)
 Set the period in micro second. More...
 
uint32_t GetPeriodUS () const
 
void SetPeriodMS (uint32_t period_ms)
 Set the period in milli second. More...
 
uint32_t GetPeriodMS () const
 
bool IsPeriodSet (void)
 Returns if period was set. More...
 
void WaitPeriod (void) const
 Wait the period. More...
 
int WaitUpdate (const IODevice *device)
 Wait update of an IODevice. More...
 
void Suspend (void)
 Suspend the thread. More...
 
bool SuspendUntil (Time date)
 Suspend the thread with timeout. More...
 
void Resume (void)
 Resume the thread. More...
 
bool IsSuspended (void) const
 Is the thread suspended? More...
 
bool IsRunning (void) const
 Is the thread running? More...
 
void SleepUntil (Time time) const
 Sleep until absolute time. More...
 
void SleepUS (uint32_t time_us) const
 Sleep for a certain time in micro second. More...
 
void SleepMS (uint32_t time_ms) const
 Sleep for a cartain time in milli second. More...
 
- Public Member Functions inherited from flair::core::Object
 Object (const Object *parent=NULL, std::string name="", std::string type="")
 Constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
std::string ObjectName (void) const
 Name. More...
 
std::string ObjectType (void) const
 Type. More...
 
const ObjectParent (void) const
 Parent. More...
 
std::vector< const Object * > * TypeChilds (void) const
 Childs of the same type. More...
 
std::vector< const Object * > * Childs (void) const
 Childs. More...
 
void Information (const char *function, int line, const char *format,...) const
 Formatted information. More...
 
void Warning (const char *function, const char *format,...) const
 Formatted warning. More...
 
void Error (const char *function, const char *format,...) const
 Formatted error. More...
 
bool ErrorOccured (bool recursive=true) const
 Has an errror occured? More...
 

Static Public Member Functions

static void WarnUponSwitches (bool enable)
 Warn if real time / non real time switches occur. More...
 

Additional Inherited Members

- Public Types inherited from flair::core::Object
enum  color_t { Auto = 0, Red = 31, Green = 32, Orange = 33 }
 

Detailed Description

Abstract class for a thread.

To implement a thread, Run() method must be reimplemented.
When Start() is called, it will automatically call Run() reimplemented method. A thread can be periodic, in this case WaitPeriod() will block untill period is met. Thread can also e synnchronized with an IODevice, using WaitUpdate() method.
Thread period is by default 100ms.

Constructor & Destructor Documentation

flair::core::Thread::Thread ( const Object parent,
std::string  name,
uint8_t  priority,
uint32_t  stackSize = 1024 *128 
)

Constructor.

Parameters
parentparent
namename
prioritypriority, should be >20 (<20 is reserved for internal use)
stackSizestack size in bytes
virtual flair::core::Thread::~Thread ( )
virtual

Destructor.

If thread is started, SafeStop() and Join() will be automatically called.

Member Function Documentation

void flair::core::Thread::Start ( void  )

Start the thread.

void flair::core::Thread::SafeStop ( void  )

Set a stop flag.

ToBeStopped() will return true after calling this method.

bool flair::core::Thread::ToBeStopped ( void  ) const

Set a stop flag.

Reimplemented Run() can poll this method to determine when to stop the thread.

Returns
true if SafeStop() was called
void flair::core::Thread::Join ( void  )

Join the thread.

This method will block untill Run() returns.

void flair::core::Thread::SetPeriodUS ( uint32_t  period_us)

Set the period in micro second.

After calling this method, IsPeriodSet will return true.

Parameters
period_usperiod in us
void flair::core::Thread::SetPeriodMS ( uint32_t  period_ms)

Set the period in milli second.

After calling this method, IsPeriodSet will return true.

Parameters
period_umsperiod in ms
bool flair::core::Thread::IsPeriodSet ( void  )

Returns if period was set.

Returns
true if a period was set using SetPeriodUS or SetPeriodMS false otherwise
void flair::core::Thread::WaitPeriod ( void  ) const

Wait the period.

This method will block untill period is met.
If no period was set (see SetPeriodUS, SetPeriodMS and IsPeriodSet), this method returns immediately.

int flair::core::Thread::WaitUpdate ( const IODevice device)

Wait update of an IODevice.

This method will block untill IODevice::ProcessUpdate is called.
This method is usefull to synchronize a thread with an IODevice.

Parameters
deviceIODevice to wait update from
void flair::core::Thread::Suspend ( void  )

Suspend the thread.

This method will block untill Resume() is called.

bool flair::core::Thread::SuspendUntil ( Time  date)

Suspend the thread with timeout.

This method will block until Resume() is called or the absolute date specified occurs

Parameters
dateabsolute date in ns
Returns
true if thread is woken up by a call to Resume, false otherwise
void flair::core::Thread::Resume ( void  )

Resume the thread.

This method will unblock the call to Suspend().

bool flair::core::Thread::IsSuspended ( void  ) const

Is the thread suspended?

Returns
true if thread is suspended
bool flair::core::Thread::IsRunning ( void  ) const

Is the thread running?

Returns
true if thread is running (call to Start). A suspended thread is running.
void flair::core::Thread::SleepUntil ( Time  time) const

Sleep until absolute time.

This method will block untill time is reached.

Parameters
timeabsolute time
void flair::core::Thread::SleepUS ( uint32_t  time_us) const

Sleep for a certain time in micro second.

This method will block untill time is elapsed.

Parameters
time_ustime to wait in micro second
void flair::core::Thread::SleepMS ( uint32_t  time_ms) const

Sleep for a cartain time in milli second.

This method will block untill time is elapsed.

Parameters
time_mstime to wait in milli second
static void flair::core::Thread::WarnUponSwitches ( bool  enable)
static

Warn if real time / non real time switches occur.

If enabled, a message with the call stack will be displayed in case of real time / non real time switches.
This method can help to debug application and see if switches occur.
Note that it as no effect if this method is called from the non real time Framework library.

Parameters
enableenable or disable warns