Mark3 Realtime Kernel
|
the Semaphore class provides Binary & Counting semaphore objects, based on BlockingObject base class. More...
#include <ksemaphore.h>
Public Member Functions | |
void * | operator new (size_t sz, void *pv) |
~Semaphore () | |
void | Init (uint16_t u16InitVal_, uint16_t u16MaxVal_) |
Initialize a semaphore before use. Must be called before attempting post/pend operations on the object. More... | |
bool | Post () |
Increment the semaphore count. If the semaphore count is zero at the time this is called, and there are threads blocked on the object, this will immediately unblock the highest-priority blocked Thread. More... | |
void | Pend () |
Decrement the semaphore count. If the count is zero, the calling Thread will block until the semaphore is posted, and the Thread's priority is higher than that of any other Thread blocked on the object. More... | |
uint16_t | GetCount () |
Return the current semaphore counter. This can be usedd by a thread to bypass blocking on a semaphore - allowing it to do other things until a non-zero count is returned, instead of blocking until the semaphore is posted. More... | |
bool | Pend (uint32_t u32WaitTimeMS_) |
Decrement the semaphore count. If the count is zero, the thread will block until the semaphore is pended. If the specified interval expires before the thread is unblocked, then the status is returned back to the user. More... | |
void | WakeMe (Thread *pclChosenOne_) |
Wake a thread blocked on the semaphore. This is an internal function used for implementing timed semaphores relying on timer callbacks. Since these do not have access to the private data of the semaphore and its base classes, we have to wrap this as a public method - do not used this for any other purposes. More... | |
Public Member Functions inherited from Mark3::BlockingObject | |
BlockingObject () | |
~BlockingObject () | |
Private Member Functions | |
uint8_t | WakeNext () |
Wake the next thread waiting on the semaphore. Used internally. More... | |
bool | Pend_i (uint32_t u32WaitTimeMS_) |
Pend_i. More... | |
Private Attributes | |
uint16_t | m_u16Value |
Current count held by the semaphore. More... | |
uint16_t | m_u16MaxValue |
Maximum count that can be held by this semaphore. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from Mark3::BlockingObject | |
void | Block (Thread *pclThread_) |
Block Blocks a thread on this object. This is the fundamental operation performed by any sort of blocking operation in the operating system. All semaphores/mutexes/sleeping/messaging/etc ends up going through the blocking code at some point as part of the code that manages a transition from an "active" or "waiting" thread to a "blocked" thread. More... | |
void | BlockPriority (Thread *pclThread_) |
BlockPriority Same as Block(), but ensures that threads are added to the block-list in priority-order, which optimizes the unblock procedure. More... | |
void | UnBlock (Thread *pclThread_) |
UnBlock Unblock a thread that is already blocked on this object, returning it to the "ready" state by performing the following steps: More... | |
void | SetInitialized (void) |
SetInitialized. More... | |
bool | IsInitialized (void) |
IsInitialized. More... | |
Protected Attributes inherited from Mark3::BlockingObject | |
ThreadList | m_clBlockList |
uint8_t | m_u8Initialized |
Static Protected Attributes inherited from Mark3::BlockingObject | |
static constexpr auto | m_uBlockingInvalidCookie = uint8_t { 0x3C } |
static constexpr auto | m_uBlockingInitCookie = uint8_t { 0xC3 } |
the Semaphore class provides Binary & Counting semaphore objects, based on BlockingObject base class.
Definition at line 36 of file ksemaphore.h.
Mark3::Semaphore::~Semaphore | ( | ) |
Definition at line 58 of file ksemaphore.cpp.
uint16_t Mark3::Semaphore::GetCount | ( | ) |
Return the current semaphore counter. This can be usedd by a thread to bypass blocking on a semaphore - allowing it to do other things until a non-zero count is returned, instead of blocking until the semaphore is posted.
Definition at line 206 of file ksemaphore.cpp.
void Mark3::Semaphore::Init | ( | uint16_t | u16InitVal_, |
uint16_t | u16MaxVal_ | ||
) |
Initialize a semaphore before use. Must be called before attempting post/pend operations on the object.
This initialization is required to configure the behavior of the semaphore with regards to the initial and maximum values held by the semaphore. By providing access to the raw initial and maximum count elements of the semaphore, these objects are able to be used as either counting or binary semaphores.
To configure a semaphore object for use as a binary semaphore, set values of 0 and 1 respectively for the initial/maximum value parameters.
Any other combination of values can be used to implement a counting semaphore.
u16InitVal_ | Initial value held by the semaphore |
u16MaxVal_ | Maximum value for the semaphore. Must be nonzero. |
Definition at line 94 of file ksemaphore.cpp.
|
inline |
Definition at line 39 of file ksemaphore.h.
void Mark3::Semaphore::Pend | ( | ) |
Decrement the semaphore count. If the count is zero, the calling Thread will block until the semaphore is posted, and the Thread's priority is higher than that of any other Thread blocked on the object.
Definition at line 194 of file ksemaphore.cpp.
bool Mark3::Semaphore::Pend | ( | uint32_t | u32WaitTimeMS_ | ) |
Decrement the semaphore count. If the count is zero, the thread will block until the semaphore is pended. If the specified interval expires before the thread is unblocked, then the status is returned back to the user.
Definition at line 200 of file ksemaphore.cpp.
|
private |
Pend_i.
Internal function used to abstract timed and untimed semaphore pend operations.
u32WaitTimeMS_ | Time in MS to wait |
Definition at line 152 of file ksemaphore.cpp.
bool Mark3::Semaphore::Post | ( | ) |
Increment the semaphore count. If the semaphore count is zero at the time this is called, and there are threads blocked on the object, this will immediately unblock the highest-priority blocked Thread.
Note that if the priority of that Thread is higher than the current thread's priority, a context switch will occur and control will be relinquished to that Thread.
Definition at line 108 of file ksemaphore.cpp.
void Mark3::Semaphore::WakeMe | ( | Thread * | pclChosenOne_ | ) |
Wake a thread blocked on the semaphore. This is an internal function used for implementing timed semaphores relying on timer callbacks. Since these do not have access to the private data of the semaphore and its base classes, we have to wrap this as a public method - do not used this for any other purposes.
Definition at line 68 of file ksemaphore.cpp.
|
private |
Wake the next thread waiting on the semaphore. Used internally.
Definition at line 78 of file ksemaphore.cpp.
|
private |
Maximum count that can be held by this semaphore.
Definition at line 140 of file ksemaphore.h.
|
private |
Current count held by the semaphore.
Definition at line 139 of file ksemaphore.h.