![]() |
appkit
1.5.1
RoadNarrows Robotics Application Kit
|
#include <Thread.h>
Public Types | |
| enum | ThreadState { ThreadStateUninit, ThreadStateReady, ThreadStateStart, ThreadStateRunning, ThreadStateExit } |
| Kinematics thread states. More... | |
Public Member Functions | |
| Thread (const std::string &strThreadName) | |
| Default constructor. | |
| virtual | ~Thread () |
| Destructor. | |
| virtual int | createThread (int nPriority) |
| Create the thread. More... | |
| virtual int | runThread (const double fHz) |
| Run the thread. More... | |
| virtual int | terminateThread () |
| Terminate the thread. More... | |
| virtual void | setHz (const double fHz) |
| Calculate thread new full cycle run rate. More... | |
| std::string | getThreadName () const |
| Get assigned thread name. More... | |
| int | getThreadPriority () const |
| Get thread system scheduling priority. More... | |
| double | getThreadHz () const |
| Get thread run full cycle rate. More... | |
Static Public Attributes | |
| static const int | ThreadPriorityDft = 0 |
| default thread attributes | |
| static const int | ThreadPriorityMin = 1 |
| minimum scheduling priority | |
| static const int | ThreadPriorityMax = 99 |
| maximum scheduling priority | |
| static const double | ThreadMinHz = 0.001 |
| minimum Hertz rate More... | |
Protected Member Functions | |
| void | lock () |
| Lock the I2C bus. More... | |
| void | unlock () |
| Unlock the I2C bus. More... | |
| void | setPriority (int nPriority, pthread_attr_t &attr) |
| Set real-time priority attributes of of the thread to be created. More... | |
| void | changeState (ThreadState eNewState) |
| Change the thread state. More... | |
| void | timedWait (const struct timespec &tsTimeout) |
| Timed wait until state change or time out. More... | |
| virtual void | readyBlock () |
| Block indefinitely while in the ready state. More... | |
| virtual void | schedBlock () |
| Block the thread until the next subcycle task is to be run. More... | |
| virtual void | transToReady () |
| Uninitialized to Ready state transition function. More... | |
| virtual void | transToRunning () |
| Ready to Running state transition function. More... | |
| virtual void | exec () |
| Execute task(s) within scheduled [sub]cycle. More... | |
| virtual void | transToExit () |
| Any to Exit state transition function. More... | |
Static Protected Member Functions | |
| static void * | thread (void *pArg) |
| The thread. More... | |
Protected Attributes | |
| std::string | m_strThreadName |
| thread identifying name | |
| ThreadState | m_eState |
| thread state | |
| pthread_mutex_t | m_mutexSync |
| synchonization mutex | |
| pthread_cond_t | m_condSync |
| synchonization condition | |
| pthread_t | m_thread |
| pthread identifier | |
| int | m_nPriority |
| thread OS scheduling priority | |
| double | m_fHz |
| thread cycle run rate (Hertz) | |
| double | m_fTExec |
| task execution cycle period (sec) | |
| chronos::Time | m_tExecPeriod |
| task execution period (converted) | |
| chronos::Time | m_tSched |
| working scheduler time | |
| chronos::Time | m_tExecLastTimeStamp |
| start of last execution time stamp | |
| chronos::Time | m_tExecThisTimeStamp |
| start of this execution time stamp | |
| int | m_nSlipErrCnt |
| slipped error count leaky bucket | |
|
protected |
Change the thread state.
The thread, if blocked, will be immediately unblocked to examine the new state.
| eNewState | New state. |
Definition at line 252 of file Thread.cxx.
References m_condSync, and m_eState.
Referenced by runThread(), terminateThread(), thread(), and unlock().
|
virtual |
Create the thread.
The thread remains blocked in the ready state until runThread() is called.
| nPriority | Thread OS scheduling priority. |
Definition at line 87 of file Thread.cxx.
References lock(), m_condSync, m_eState, m_mutexSync, m_thread, setPriority(), thread(), ThreadPriorityDft, ThreadStateExit, ThreadStateUninit, and unlock().
Referenced by mainInit().
|
protectedvirtual |
Execute task(s) within scheduled [sub]cycle.
This function is called every cycle in the Running state.
A hook for any derived thread class. A simple debug print execution for the base class.
This function executes under the lock/unlock mutex.
Reimplemented in UTThread.
Definition at line 363 of file Thread.cxx.
References m_strThreadName, m_tExecLastTimeStamp, m_tExecThisTimeStamp, and rnr::chronos::Time::ts().
Referenced by thread(), and unlock().
|
inline |
|
inline |
Get assigned thread name.
Definition at line 152 of file Thread.h.
References m_strThreadName.
|
inline |
Get thread system scheduling priority.
Definition at line 162 of file Thread.h.
References m_nPriority.
|
inlineprotected |
Lock the I2C bus.
The lock()/unlock() primitives provide safe multi-threading access.
Definition at line 203 of file Thread.h.
Referenced by createThread(), readyBlock(), setHz(), thread(), and timedWait().
|
protectedvirtual |
Block indefinitely while in the ready state.
Definition at line 267 of file Thread.cxx.
References lock(), m_condSync, m_eState, m_mutexSync, ThreadStateReady, and unlock().
Referenced by thread(), and unlock().
|
virtual |
Run the thread.
| fHZ | Thread run rate (Hertz). |
Definition at line 189 of file Thread.cxx.
References changeState(), m_eState, m_strThreadName, setHz(), ThreadStateExit, ThreadStateReady, ThreadStateRunning, and ThreadStateStart.
Referenced by mainInit().
|
protectedvirtual |
Block the thread until the next subcycle task is to be run.
Definition at line 279 of file Thread.cxx.
References m_nSlipErrCnt, m_strThreadName, m_tExecPeriod, m_tSched, rnr::chronos::Time::markNow(), timedWait(), and rnr::chronos::Time::ts().
Referenced by thread(), and unlock().
|
virtual |
Calculate thread new full cycle run rate.
| fHZ | Thread run rate (Hertz). |
Definition at line 229 of file Thread.cxx.
References lock(), m_fHz, m_fTExec, m_nSlipErrCnt, m_tExecPeriod, ThreadMinHz, and unlock().
Referenced by runThread().
|
protected |
Set real-time priority attributes of of the thread to be created.
Definition at line 132 of file Thread.cxx.
References m_nPriority, ThreadPriorityMax, and ThreadPriorityMin.
Referenced by createThread(), and unlock().
|
virtual |
Terminate the thread.
This function does not return until the thread actually terminates.
Definition at line 217 of file Thread.cxx.
References changeState(), m_eState, m_thread, ThreadStateExit, ThreadStateReady, ThreadStateRunning, and ThreadStateStart.
Referenced by mainInit(), and ~Thread().
|
staticprotected |
The thread.
| pArg | Thread argument (pointer to this object). |
Definition at line 382 of file Thread.cxx.
References changeState(), exec(), lock(), m_eState, m_fHz, m_nPriority, m_strThreadName, m_tExecLastTimeStamp, m_tExecThisTimeStamp, m_tSched, rnr::chronos::Time::markNow(), readyBlock(), schedBlock(), ThreadStateExit, ThreadStateReady, ThreadStateRunning, ThreadStateStart, transToExit(), transToReady(), transToRunning(), and unlock().
Referenced by createThread(), and unlock().
|
protected |
Timed wait until state change or time out.
| tsTimeout | When timeout occurs in absolute time. |
Definition at line 258 of file Thread.cxx.
References lock(), m_condSync, m_mutexSync, and unlock().
Referenced by schedBlock(), and unlock().
|
protectedvirtual |
Any to Exit state transition function.
This function is called after entering the Exit state but prior to terminating the thread.
A hook for any derived thread class. A no-op for the base class.
This function does not execute under the lock/unlock mutex.
Reimplemented in UTThread.
Definition at line 378 of file Thread.cxx.
|
protectedvirtual |
Uninitialized to Ready state transition function.
This function is called after entering the Ready state but prior to being blocked waiting to be run.
A hook for any derived thread class. A no-op for the base class.
This function does not execute under the lock/unlock mutex.
Reimplemented in UTThread.
Definition at line 355 of file Thread.cxx.
|
protectedvirtual |
Ready to Running state transition function.
This function is called after entering the Running state but prior to any run execution.
A hook for any derived thread class. A no-op for the base class.
This function does not execute under the lock/unlock mutex.
Reimplemented in UTThread.
Definition at line 359 of file Thread.cxx.
|
inlineprotected |
Unlock the I2C bus.
The lock()/unlock() primitives provide safe multi-threading access.
Definition at line 217 of file Thread.h.
References changeState(), exec(), readyBlock(), schedBlock(), setPriority(), thread(), timedWait(), transToExit(), transToReady(), and transToRunning().
Referenced by createThread(), readyBlock(), setHz(), thread(), and timedWait().
|
static |