Flair
Framework Libre Air
|
Abstract class for a thread. More...
#include <Thread.h>
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 Object * | Parent (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 } |
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.
flair::core::Thread::Thread | ( | const Object * | parent, |
std::string | name, | ||
uint8_t | priority, | ||
uint32_t | stackSize = 1024 *128 |
||
) |
Constructor.
parent | parent |
name | name |
priority | priority, should be >20 (<20 is reserved for internal use) |
stackSize | stack size in bytes |
|
virtual |
Destructor.
If thread is started, SafeStop() and Join() will be automatically called.
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.
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.
period_us | period 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.
period_ums | period in ms |
bool flair::core::Thread::IsPeriodSet | ( | void | ) |
Returns if period was set.
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.
device | IODevice 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
date | absolute date in ns |
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?
bool flair::core::Thread::IsRunning | ( | void | ) | const |
Is the thread running?
void flair::core::Thread::SleepUntil | ( | Time | time | ) | const |
Sleep until absolute time.
This method will block untill time is reached.
time | absolute 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.
time_us | time 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.
time_ms | time to wait in milli second |
|
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.
enable | enable or disable warns |