Mark3 Realtime Kernel
|
The Thread Class. This object providing the fundamental thread control data structures and functions that define a single thread of execution in the Mark3 operating system. It is the fundamental data type used to provide multitasking support in the kernel. More...
#include <thread.h>
Public Member Functions | |
void * | operator new (size_t sz, void *pv) |
~Thread () | |
Thread () | |
bool | IsInitialized () |
IsInitialized Used to check whether or not a thread has been initialized prior to use. More... | |
void | Init (K_WORD *pwStack_, uint16_t u16StackSize_, PORT_PRIO_TYPE uXPriority_, ThreadEntryFunc pfEntryPoint_, void *pvArg_) |
Init Initialize a thread prior to its use. Initialized threads are placed in the stopped state, and are not scheduled until the thread's start method has been invoked first. More... | |
void | Start () |
Start Start the thread - remove it from the stopped list, add it to the scheduler's list of threads (at the thread's set priority), and continue along. More... | |
void | Stop () |
Stop Stop a thread that's actively scheduled without destroying its stacks. Stopped threads can be restarted using the Start() API. More... | |
void | SetName (const char *szName_) |
SetName Set the name of the thread - this is purely optional, but can be useful when identifying issues that come along when multiple threads are at play in a system. More... | |
const char * | GetName () |
GetName. More... | |
ThreadList * | GetOwner (void) |
GetOwner Return the ThreadList where the thread belongs when it's in the active/ready state in the scheduler. More... | |
ThreadList * | GetCurrent (void) |
GetCurrent Return the ThreadList where the thread is currently located. More... | |
PORT_PRIO_TYPE | GetPriority (void) |
GetPriority Return the priority of the current thread. More... | |
PORT_PRIO_TYPE | GetCurPriority (void) |
GetCurPriority Return the priority of the current thread. More... | |
void | SetQuantum (uint16_t u16Quantum_) |
SetQuantum Set the thread's round-robin execution quantum. More... | |
uint16_t | GetQuantum (void) |
GetQuantum Get the thread's round-robin execution quantum. More... | |
void | SetCurrent (ThreadList *pclNewList_) |
SetCurrent. Set the thread's current to the specified thread list. More... | |
void | SetOwner (ThreadList *pclNewList_) |
SetOwner. Set the thread's owner to the specified thread list. More... | |
void | SetPriority (PORT_PRIO_TYPE uXPriority_) |
SetPriority. Set the priority of the Thread (running or otherwise) to a different level. This activity involves re-scheduling, and must be done so with due caution, as it may effect the determinism of the system. More... | |
void | InheritPriority (PORT_PRIO_TYPE uXPriority_) |
InheritPriority Allow the thread to run at a different priority level (temporarily) for the purpose of avoiding priority inversions. This should only be called from within the implementation of blocking-objects. More... | |
void | Exit () |
Exit. Remove the thread from being scheduled again. The thread is effectively destroyed when this occurs. This is extremely useful for cases where a thread encounters an unrecoverable error and needs to be restarted, or in the context of systems where threads need to be created and destroyed dynamically. More... | |
void | SetID (uint8_t u8ID_) |
SetID Set an arbitrary 8-bit ID to uniquely identify this thread. More... | |
uint8_t | GetID () |
GetID Return the thread's integer ID. Note that this ID is not guaranteed to be unique when dynamic threading is used in the system, or there are more than 255 threads. Also not guaranteed to be unique if the SetID function is called by the user. More... | |
uint16_t | GetStackSlack () |
GetStackSlack Performs a (somewhat lengthy) check on the thread stack to check the amount of stack margin (or "slack") remaining on the stack. If you're having problems with blowing your stack, you can run this function at points in your code during development to see what operations cause problems. Also useful during development as a tool to optimally size thread stacks. More... | |
uint16_t | GetEventFlagMask () |
GetEventFlagMask returns the thread's current event-flag mask, which is used in conjunction with the EventFlag blocking object type. More... | |
void | SetEventFlagMask (uint16_t u16Mask_) |
SetEventFlagMask Sets the active event flag bitfield mask. More... | |
void | SetEventFlagMode (EventFlagOperation eMode_) |
SetEventFlagMode Sets the active event flag operation mode. More... | |
EventFlagOperation | GetEventFlagMode () |
GetEventFlagMode Returns the thread's event flag's operating mode. More... | |
Timer * | GetTimer () |
void | SetExpired (bool bExpired_) |
SetExpired Set the status of the current blocking call on the thread. More... | |
bool | GetExpired () |
GetExpired Return the status of the most-recent blocking call on the thread. More... | |
void * | GetExtendedContext () |
GetExtendedContext Return the Thread object's extended-context data pointer. Used by code implementing a user-defined thread-local storage model. Pointer exists only for the lifespan of the Thread. More... | |
void | SetExtendedContext (void *pvData_) |
SetExtendedContext Assign the Thread object's extended-context data pointer. Used by code implementing a user-defined thread-local storage model. More... | |
ThreadState | GetState () |
GetState Returns the current state of the thread to the caller. Can be used to determine whether or not a thread is ready (or running), stopped, or terminated/exit'd. More... | |
void | SetState (ThreadState eState_) |
SetState Set the thread's state to a new value. This is only to be used by code within the kernel, and is not indended for use by an end-user. More... | |
K_WORD * | GetStack () |
GetStack. More... | |
K_WORD * | GetStackTop () |
GetStackTop. More... | |
uint16_t | GetStackSize () |
GetStackSize. More... | |
int * | ErrnoStorage () |
ErrnoStorage. More... | |
Public Member Functions inherited from Mark3::TypedLinkListNode< Thread > | |
Thread * | GetNext () |
Thread * | GetPrev () |
Public Member Functions inherited from Mark3::LinkListNode | |
LinkListNode * | GetNext (void) |
GetNext. More... | |
LinkListNode * | GetPrev (void) |
GetPrev. More... | |
Static Public Member Functions | |
static Thread * | Init (uint16_t u16StackSize_, PORT_PRIO_TYPE uXPriority_, ThreadEntryFunc pfEntryPoint_, void *pvArg_) |
Init Create and initialize a new thread, using memory from the auto-allocated heap region to supply both the thread object and its stack. The thread returned can then be started using the Start() method directly. Note that the memory used to create this thread cannot be reclaimed, and so this API is only suitable for threads that exist for the duration of runtime. More... | |
static void | Sleep (uint32_t u32TimeMs_) |
Sleep Put the thread to sleep for the specified time (in milliseconds). Actual time slept may be longer (but not less than) the interval specified. More... | |
static void | Yield (void) |
Yield Yield the thread - this forces the system to call the scheduler and determine what thread should run next. This is typically used when threads are moved in and out of the scheduler. More... | |
static void | CoopYield (void) |
CoopYield Cooperative yield - This forces the system to not only call the scheduler, but also move the currently executing thread to the back of the current thread list, allowing other same-priority threads the opportunity to run. This is used primarily for cooperative scheduling between threads in the same priority level. More... | |
Private Member Functions | |
void | SetPriorityBase (PORT_PRIO_TYPE uXPriority_) |
SetPriorityBase. More... | |
Static Private Member Functions | |
static void | ContextSwitchSWI (void) |
ContextSwitchSWI This code is used to trigger the context switch interrupt. Called whenever the kernel decides that it is necessary to swap out the current thread for the "next" thread. More... | |
Private Attributes | |
K_WORD * | m_pwStackTop |
Pointer to the top of the thread's stack. More... | |
K_WORD * | m_pwStack |
Pointer to the thread's stack. More... | |
uint8_t | m_u8ThreadID |
Thread ID. More... | |
PORT_PRIO_TYPE | m_uXPriority |
Default priority of the thread. More... | |
PORT_PRIO_TYPE | m_uXCurPriority |
Current priority of the thread (priority inheritence) More... | |
ThreadState | m_eState |
Enum indicating the thread's current state. More... | |
void * | m_pvExtendedContext |
Pointer provided to a Thread to implement thread-local storage. More... | |
const char * | m_szName |
Thread name. More... | |
uint16_t | m_u16StackSize |
Size of the stack (in bytes) More... | |
ThreadList * | m_pclCurrent |
Pointer to the thread-list where the thread currently resides. More... | |
ThreadList * | m_pclOwner |
Pointer to the thread-list where the thread resides when active. More... | |
ThreadEntryFunc | m_pfEntryPoint |
The entry-point function called when the thread starts. More... | |
void * | m_pvArg |
Pointer to the argument passed into the thread's entrypoint. More... | |
uint16_t | m_u16Quantum |
Thread quantum (in milliseconds) More... | |
uint16_t | m_u16FlagMask |
Event-flag mask. More... | |
EventFlagOperation | m_eFlagMode |
Event-flag mode. More... | |
bool | m_bExpired |
Indicate whether or not a blocking-object timeout has occurred. More... | |
int | m_iErrno |
Storage used to hold a thread-safe errno value. More... | |
Timer | m_clTimer |
Timer used for blocking-object timeouts. More... | |
Friends | |
class | ThreadPort |
Additional Inherited Members | |
Protected Member Functions inherited from Mark3::LinkListNode | |
LinkListNode () | |
void | ClearNode () |
ClearNode. More... | |
Protected Attributes inherited from Mark3::LinkListNode | |
LinkListNode * | next |
Pointer to the next node in the list. More... | |
LinkListNode * | prev |
Pointer to the previous node in the list. More... | |
The Thread Class. This object providing the fundamental thread control data structures and functions that define a single thread of execution in the Mark3 operating system. It is the fundamental data type used to provide multitasking support in the kernel.
Mark3::Thread::~Thread | ( | ) |
Definition at line 30 of file thread.cpp.
|
staticprivate |
ContextSwitchSWI This code is used to trigger the context switch interrupt. Called whenever the kernel decides that it is necessary to swap out the current thread for the "next" thread.
Definition at line 391 of file thread.cpp.
|
static |
CoopYield Cooperative yield - This forces the system to not only call the scheduler, but also move the currently executing thread to the back of the current thread list, allowing other same-priority threads the opportunity to run. This is used primarily for cooperative scheduling between threads in the same priority level.
Definition at line 324 of file thread.cpp.
|
inline |
void Mark3::Thread::Exit | ( | ) |
Exit. Remove the thread from being scheduled again. The thread is effectively destroyed when this occurs. This is extremely useful for cases where a thread encounters an unrecoverable error and needs to be restarted, or in the context of systems where threads need to be created and destroyed dynamically.
This must not be called on the idle thread.
Definition at line 187 of file thread.cpp.
|
inline |
|
inline |
GetCurrent Return the ThreadList where the thread is currently located.
|
inline |
|
inline |
bool Mark3::Thread::GetExpired | ( | ) |
GetExpired Return the status of the most-recent blocking call on the thread.
Definition at line 424 of file thread.cpp.
|
inline |
|
inline |
GetID Return the thread's integer ID. Note that this ID is not guaranteed to be unique when dynamic threading is used in the system, or there are more than 255 threads. Also not guaranteed to be unique if the SetID function is called by the user.
|
inline |
|
inline |
GetOwner Return the ThreadList where the thread belongs when it's in the active/ready state in the scheduler.
|
inline |
|
inline |
|
inline |
|
inline |
uint16_t Mark3::Thread::GetStackSlack | ( | ) |
GetStackSlack Performs a (somewhat lengthy) check on the thread stack to check the amount of stack margin (or "slack") remaining on the stack. If you're having problems with blowing your stack, you can run this function at points in your code during development to see what operations cause problems. Also useful during development as a tool to optimally size thread stacks.
|
inline |
GetStackTop.
|
inline |
GetState Returns the current state of the thread to the caller. Can be used to determine whether or not a thread is ready (or running), stopped, or terminated/exit'd.
Timer * Mark3::Thread::GetTimer | ( | ) |
Return a pointer to the thread's timer object
Definition at line 411 of file thread.cpp.
void Mark3::Thread::InheritPriority | ( | PORT_PRIO_TYPE | uXPriority_ | ) |
InheritPriority Allow the thread to run at a different priority level (temporarily) for the purpose of avoiding priority inversions. This should only be called from within the implementation of blocking-objects.
uXPriority_ | New Priority to boost to. |
Definition at line 382 of file thread.cpp.
void Mark3::Thread::Init | ( | K_WORD * | pwStack_, |
uint16_t | u16StackSize_, | ||
PORT_PRIO_TYPE | uXPriority_, | ||
ThreadEntryFunc | pfEntryPoint_, | ||
void * | pvArg_ | ||
) |
Init Initialize a thread prior to its use. Initialized threads are placed in the stopped state, and are not scheduled until the thread's start method has been invoked first.
pwStack_ | Pointer to the stack to use for the thread |
u16StackSize_ | Size of the stack (in bytes) |
uXPriority_ | Priority of the thread (0 = idle, 7 = max) |
pfEntryPoint_ | This is the function that gets called when the thread is started |
pvArg_ | Pointer to the argument passed into the thread's entrypoint function. |
Definition at line 49 of file thread.cpp.
|
static |
Init Create and initialize a new thread, using memory from the auto-allocated heap region to supply both the thread object and its stack. The thread returned can then be started using the Start() method directly. Note that the memory used to create this thread cannot be reclaimed, and so this API is only suitable for threads that exist for the duration of runtime.
u16StackSize_ | Size of the stack (in bytes) |
uXPriority_ | Priority of the thread (0 = idle, 7 = max) |
pfEntryPoint_ | This is the function that gets called when the thread is started |
pvArg_ | Pointer to the argument passed into the thread's entrypoint function. |
Definition at line 101 of file thread.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void Mark3::Thread::SetExpired | ( | bool | bExpired_ | ) |
SetExpired Set the status of the current blocking call on the thread.
bExpired_ | true - call expired, false - call did not expire |
Definition at line 417 of file thread.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
void Mark3::Thread::SetPriority | ( | PORT_PRIO_TYPE | uXPriority_ | ) |
SetPriority. Set the priority of the Thread (running or otherwise) to a different level. This activity involves re-scheduling, and must be done so with due caution, as it may effect the determinism of the system.
This should always be called from within a critical section to prevent system issues.
uXPriority_ | New priority of the thread |
Definition at line 341 of file thread.cpp.
|
private |
|
inline |
|
inline |
|
static |
Sleep Put the thread to sleep for the specified time (in milliseconds). Actual time slept may be longer (but not less than) the interval specified.
u32TimeMs_ | Time to sleep (in ms) |
Definition at line 249 of file thread.cpp.
void Mark3::Thread::Start | ( | void | ) |
Start Start the thread - remove it from the stopped list, add it to the scheduler's list of threads (at the thread's set priority), and continue along.
Definition at line 110 of file thread.cpp.
void Mark3::Thread::Stop | ( | void | ) |
Stop Stop a thread that's actively scheduled without destroying its stacks. Stopped threads can be restarted using the Start() API.
Definition at line 141 of file thread.cpp.
|
static |
Yield Yield the thread - this forces the system to call the scheduler and determine what thread should run next. This is typically used when threads are moved in and out of the scheduler.
Definition at line 304 of file thread.cpp.
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |