![]() |
Laelaps
2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
|
#include <laeThread.h>
Public Types | |
enum | ThreadState { ThreadStateUninit, ThreadStateReady, ThreadStateStart, ThreadStateRunning, ThreadStateExit } |
Kinematics thread states. More... | |
Public Member Functions | |
LaeThread (const std::string &strThreadName) | |
Default constructor. | |
virtual | ~LaeThread () |
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 | ThreadPriorityMin = 1 |
minimum scheduling priority | |
static const int | ThreadPriorityMax = 99 |
maximum scheduling priority | |
static const double | ThreadMinHz = 0.001 |
minimum thread Hertz More... | |
Protected Member Functions | |
void | lock () |
Lock the I2C bus. More... | |
void | unlock () |
Unlock the I2C bus. 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 (seconds) | |
struct timespec | m_tsExecPeriod |
task execution period (converted) | |
struct timespec | m_tsJitter |
allowable scheduling jitter | |
struct timespec | m_tsSched |
working scheduler time stamp | |
struct timespec | m_tsExecLast |
start of last execution time stamp | |
struct timespec | m_tsExecThis |
start of this execution time stamp | |
int | m_nSlipErrCnt |
slipped error count leaky bucket | |
Thread base class.
Definition at line 77 of file laeThread.h.
enum laelaps::LaeThread::ThreadState |
Kinematics thread states.
Definition at line 93 of file laeThread.h.
|
protected |
Change the thread state.
The thread, if blocked, will be immediately unblocked to examine the new state.
eNewState | New state. |
Definition at line 244 of file laeThread.cxx.
References m_condSync, and m_eState.
Referenced by laelaps::LaeThreadAsync::exec(), 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 107 of file laeThread.cxx.
References laelaps::cap(), laelaps::LAE_ECODE_NO_EXEC, laelaps::LAE_OK, lock(), m_condSync, m_eState, m_mutexSync, m_nPriority, m_thread, thread(), ThreadPriorityMax, ThreadPriorityMin, ThreadStateExit, ThreadStateUninit, and unlock().
Referenced by laelaps::LaeThreadAsync::createThread(), mainInit(), and laelaps::LaeRobot::startThread().
|
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 laelaps::LaeThreadAsync, UTThread, laelaps::LaeThreadKin, laelaps::LaeThreadWd, laelaps::LaeThreadRange, and laelaps::LaeThreadImu.
Definition at line 350 of file laeThread.cxx.
References m_strThreadName, m_tsExecLast, and m_tsExecThis.
Referenced by thread(), and unlock().
|
inline |
Get thread run full cycle rate.
Definition at line 189 of file laeThread.h.
References m_fHz.
|
inline |
Get assigned thread name.
Definition at line 169 of file laeThread.h.
References m_strThreadName.
Referenced by laelaps::LaeRobot::startThread().
|
inline |
Get thread system scheduling priority.
Definition at line 179 of file laeThread.h.
References m_nPriority.
|
inlineprotected |
Lock the I2C bus.
The lock()/unlock() primitives provide safe multi-threading access.
Definition at line 221 of file laeThread.h.
Referenced by createThread(), readyBlock(), laelaps::LaeThreadImu::reload(), laelaps::LaeThreadRange::reload(), laelaps::LaeThreadKin::reload(), laelaps::LaeThreadWd::reload(), setHz(), thread(), timedWait(), and laelaps::LaeThreadKin::waitOneCycle().
|
protectedvirtual |
Block indefinitely while in the ready state.
Definition at line 259 of file laeThread.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). |
Reimplemented in laelaps::LaeThreadAsync.
Definition at line 174 of file laeThread.cxx.
References changeState(), laelaps::LAE_ECODE_GEN, laelaps::LAE_OK, m_eState, m_strThreadName, setHz(), ThreadStateExit, ThreadStateReady, ThreadStateRunning, and ThreadStateStart.
Referenced by mainInit(), laelaps::LaeThreadAsync::runThread(), and laelaps::LaeRobot::startThread().
|
protectedvirtual |
Block the thread until the next subcycle task is to be run.
Definition at line 271 of file laeThread.cxx.
References m_nSlipErrCnt, m_strThreadName, m_tsExecPeriod, m_tsJitter, m_tsSched, and timedWait().
Referenced by thread(), and unlock().
|
virtual |
Calculate thread new full cycle run rate.
fHZ | Thread run rate (Hertz). |
Definition at line 214 of file laeThread.cxx.
References laelaps::fcap(), lock(), m_fHz, m_fTExec, m_nSlipErrCnt, m_tsExecPeriod, m_tsJitter, ThreadMinHz, and unlock().
Referenced by laelaps::LaeThreadImu::reload(), laelaps::LaeThreadRange::reload(), laelaps::LaeThreadKin::reload(), and runThread().
|
virtual |
Terminate the thread.
This function does not return until the thread actually terminates.
Reimplemented in laelaps::LaeThreadAsync.
Definition at line 202 of file laeThread.cxx.
References changeState(), laelaps::LAE_OK, m_eState, m_thread, ThreadStateExit, ThreadStateReady, ThreadStateRunning, and ThreadStateStart.
Referenced by laelaps::LaeRobot::disconnect(), mainInit(), laelaps::LaeThreadAsync::terminateThread(), and ~LaeThread().
|
staticprotected |
The thread.
pArg | Thread argument (pointer to this object). |
Definition at line 366 of file laeThread.cxx.
References changeState(), exec(), lock(), m_eState, m_fHz, m_nPriority, m_strThreadName, m_tsExecLast, m_tsExecThis, m_tsSched, 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 250 of file laeThread.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 laelaps::LaeThreadAsync, and UTThread.
Definition at line 362 of file laeThread.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 laelaps::LaeThreadAsync, and UTThread.
Definition at line 342 of file laeThread.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 laelaps::LaeThreadAsync, UTThread, and laelaps::LaeThreadKin.
Definition at line 346 of file laeThread.cxx.
|
inlineprotected |
Unlock the I2C bus.
The lock()/unlock() primitives provide safe multi-threading access.
Definition at line 235 of file laeThread.h.
References changeState(), exec(), readyBlock(), schedBlock(), thread(), timedWait(), transToExit(), transToReady(), and transToRunning().
Referenced by createThread(), readyBlock(), laelaps::LaeThreadImu::reload(), laelaps::LaeThreadRange::reload(), laelaps::LaeThreadKin::reload(), laelaps::LaeThreadWd::reload(), setHz(), thread(), timedWait(), and laelaps::LaeThreadKin::waitOneCycle().
|
static |
minimum thread Hertz
once every 1000 seconds
Definition at line 88 of file laeThread.h.
Referenced by LaeThread(), and setHz().