CppELib 1.7.0
|
Abstract class that has functions of common RTOS's thread. More...
#include <Thread.h>
Classes | |
class | UncaughtExceptionHandler |
Interface for handling uncaught exception. More... | |
Public Member Functions | |
virtual void | start ()=0 |
Transit this thread to the READY state. | |
virtual Error | wait ()=0 |
Block the current thread until this thread transits to the FINISHED state. | |
virtual Error | tryWait ()=0 |
Query without blocking whether this thread is in the FINISHED state. | |
virtual Error | timedWait (Timeout tmout)=0 |
Block the current thread until this thread transits to the FINISHED state but only within the limited time. | |
virtual bool | isFinished () const =0 |
Return true if this thread is in the FINISHED state. | |
virtual void | setName (const char *name)=0 |
Set the object's name. | |
virtual const char * | getName () const =0 |
Get the object's name. | |
virtual void | setPriority (int priority)=0 |
Change this thread priority. | |
virtual int | getPriority () const =0 |
Get this thread priority. | |
virtual int | getInitialPriority () const =0 |
Get this thread priority when this thread was created. | |
virtual std::size_t | getStackSize () const =0 |
Get the stack size of this thread. | |
virtual void * | getNativeHandle ()=0 |
Get the native handle of RTOS's thread. | |
void | setUncaughtExceptionHandler (UncaughtExceptionHandler *handler) |
Set the UncaughtExceptionHandler for this Thread. | |
UncaughtExceptionHandler * | getUncaughtExceptionHandler () const |
Get the UncaughtExceptionHandler for this Thread. | |
Static Public Member Functions | |
static void | setDefaultUncaughtExceptionHandler (UncaughtExceptionHandler *handler) |
Set the default UncaughtExceptionHandler for all the Thread. | |
static UncaughtExceptionHandler * | getDefaultUncaughtExceptionHandler () |
Get the default UncaughtExceptionHandler. | |
static Thread * | create (Runnable *r, int priority=INHERIT_PRIORITY, std::size_t stackSize=0U, void *stackAddress=0, const char *name="") |
Create a Thread object. | |
static void | destroy (Thread *t) |
Destroy a Thread object. | |
static void | sleep (unsigned long millis) |
Sleep the current thread while the time that is set by argument. | |
static void | yield () |
Transit the current thread from the RUNNING state to the READY state to give other thread the RUNNING state. | |
static Thread * | getCurrentThread () |
Get the current running Thread object. | |
static int | getMaxPriority () |
Get the maximum value of RTOS's thread priority. | |
static int | getMinPriority () |
Get the minimum value of RTOS's thread priority. | |
static int | getNormalPriority () |
Get the middle priority between the minimum and maximum value. | |
static int | getHighestPriority () |
Get the highest thread priority of RTOS. | |
static int | getLowestPriority () |
Get the lowest thread priority of RTOS. | |
static int | getPriorityHigherThan (int basePriority, int d) |
Get the thread priority of RTOS higher than basePriority by d . | |
Static Public Attributes | |
static const int | INHERIT_PRIORITY = -1 |
Use when set the same priority as the caller thread. | |
Protected Member Functions | |
Thread (Runnable *r) | |
virtual | ~Thread () |
void | threadMain () |
Common thread main method. | |
Abstract class that has functions of common RTOS's thread.
This is the state machine diagram of Thread.
When the current thread calls some methods (for example Thread::wait(), Mutex::lock(), EventFlag::timedWait(), Thread::sleep(), etc), the state of current thread transits from RUNNING to WAITING. Then the waiting condition is satisfied or timed out, the state transits from WAITING to READY.
When the current thread runs through the end of Runnable::run(), the state of current thread transits from RUNNING to FINISHED.
|
inlineexplicitprotected |
|
inlineprotectedvirtual |
|
static |
Create a Thread object.
r | Pointer of Runnable object |
priority | Thread priority. If INHERIT_PRIORITY then sets the priority of the caller thread. |
stackSize | Stack size of thread. If zero then sets default stack size of RTOS. |
stackAddress | Stack address of thread allocated by the caller. If null pointer then RTOS allocates the stack. |
name | Name of the object |
|
static |
Destroy a Thread object.
t | Pointer of Thread object created by Thread::create() |
|
static |
Get the current running Thread object.
|
static |
Get the default UncaughtExceptionHandler.
|
static |
Get the highest thread priority of RTOS.
|
pure virtual |
Get this thread priority when this thread was created.
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
|
static |
Get the lowest thread priority of RTOS.
|
static |
Get the maximum value of RTOS's thread priority.
|
static |
Get the minimum value of RTOS's thread priority.
|
pure virtual |
Get the object's name.
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
|
pure virtual |
Get the native handle of RTOS's thread.
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
|
static |
Get the middle priority between the minimum and maximum value.
|
pure virtual |
Get this thread priority.
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
|
static |
Get the thread priority of RTOS higher than basePriority
by d
.
basePriority | Base priority |
d | Difference |
d
is positive number, returns the priority higher than basePriority
by d
. d
is negative number, returns the priority lower than basePriority
by d
. d
is zero, returns basePriority
.
|
pure virtual |
Get the stack size of this thread.
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
Thread::UncaughtExceptionHandler * OSWrapper::Thread::getUncaughtExceptionHandler | ( | ) | const |
Get the UncaughtExceptionHandler for this Thread.
|
pure virtual |
Return true if this thread is in the FINISHED state.
true | This thread is in the FINISHED state |
false | This thread is not in the FINISHED state |
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
|
static |
Set the default UncaughtExceptionHandler for all the Thread.
handler | Pointer of UncaughtExceptionHandler object |
|
pure virtual |
Set the object's name.
name | The object's name |
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
|
pure virtual |
Change this thread priority.
priority | Thread priority |
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
void OSWrapper::Thread::setUncaughtExceptionHandler | ( | Thread::UncaughtExceptionHandler * | handler | ) |
Set the UncaughtExceptionHandler for this Thread.
handler | Pointer of UncaughtExceptionHandler object |
|
static |
Sleep the current thread while the time that is set by argument.
millis | Time in milliseconds |
|
pure virtual |
Transit this thread to the READY state.
After this method, when this thread transits to the RUNNING state, this thread calls Runnable::run() specified at create().
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
|
protected |
Common thread main method.
Block the current thread until this thread transits to the FINISHED state but only within the limited time.
tmout | The limited time |
OK | Success. This thread is in the FINISHED state |
TimedOut | The limited time was elapsed |
CalledByNonThread | Called from non thread context (interrupt handler, timer, etc) |
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
|
pure virtual |
Query without blocking whether this thread is in the FINISHED state.
OK | This thread is already in the FINISHED state |
TimedOut | This thread is not in the FINISHED state |
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
|
pure virtual |
Block the current thread until this thread transits to the FINISHED state.
OK | Success. This thread is in the FINISHED state |
CalledByNonThread | Called from non thread context (interrupt handler, timer, etc) |
Implemented in StdCppOSWrapper::StdCppThreadFactory::StdCppThread, and TestDoubleOSWrapper::TestDoubleThread.
|
static |
Transit the current thread from the RUNNING state to the READY state to give other thread the RUNNING state.
|
static |
Use when set the same priority as the caller thread.