Mark3 Realtime Kernel
Mark3::EventFlag Class Reference

The EventFlag class. This class implements a blocking object, similar to a semaphore or mutex, commonly used for synchronizing thread execution based on events occurring within the system. Each EventFlag object contains a 16-bit bitmask, which is used to trigger events on associated threads. Threads wishing to block, waiting for a specific event to occur can wait on any pattern within this 16-bit bitmask to be set. Here, we provide the ability for a thread to block, waiting for ANY bits in a specified mask to be set, or for ALL bits within a specific mask to be set. Depending on how the object is configured, the bits that triggered the wakeup can be automatically cleared once a match has occurred. More...

#include <eventflag.h>

Inheritance diagram for Mark3::EventFlag:
Mark3::BlockingObject

Public Member Functions

void * operator new (size_t sz, void *pv)
 
 ~EventFlag ()
 
void Init ()
 Init Initializes the EventFlag object prior to use. More...
 
uint16_t Wait (uint16_t u16Mask_, EventFlagOperation eMode_)
 Wait Block a thread on the specific flags in this event flag group. More...
 
uint16_t Wait (uint16_t u16Mask_, EventFlagOperation eMode_, uint32_t u32TimeMS_)
 Wait Block a thread on the specific flags in this event flag group. More...
 
void WakeMe (Thread *pclChosenOne_)
 WakeMe Wake the given thread, currently blocking on this object. More...
 
void Set (uint16_t u16Mask_)
 Set Set additional flags in this object (logical OR). This API can potentially result in threads blocked on Wait() to be unblocked. More...
 
void Clear (uint16_t u16Mask_)
 ClearFlags - Clear a specific set of flags within this object, specific by bitmask. More...
 
uint16_t GetMask ()
 GetMask Returns the state of the 16-bit bitmask within this object. More...
 
- Public Member Functions inherited from Mark3::BlockingObject
 BlockingObject ()
 
 ~BlockingObject ()
 

Private Member Functions

uint16_t Wait_i (uint16_t u16Mask_, EventFlagOperation eMode_, uint32_t u32TimeMS_)
 Wait_i Interal abstraction used to manage both timed and untimed wait operations. More...
 

Private Attributes

uint16_t m_u16SetMask
 Event flags currently set in this object. 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 }
 

Detailed Description

The EventFlag class. This class implements a blocking object, similar to a semaphore or mutex, commonly used for synchronizing thread execution based on events occurring within the system. Each EventFlag object contains a 16-bit bitmask, which is used to trigger events on associated threads. Threads wishing to block, waiting for a specific event to occur can wait on any pattern within this 16-bit bitmask to be set. Here, we provide the ability for a thread to block, waiting for ANY bits in a specified mask to be set, or for ALL bits within a specific mask to be set. Depending on how the object is configured, the bits that triggered the wakeup can be automatically cleared once a match has occurred.

Examples:
lab7_events/main.cpp.

Definition at line 45 of file eventflag.h.

Constructor & Destructor Documentation

◆ ~EventFlag()

Mark3::EventFlag::~EventFlag ( )

Member Function Documentation

◆ Clear()

void Mark3::EventFlag::Clear ( uint16_t  u16Mask_)

ClearFlags - Clear a specific set of flags within this object, specific by bitmask.

Parameters
u16Mask_- Bitmask of flags to clear
Examples:
lab7_events/main.cpp.

◆ GetMask()

uint16_t Mark3::EventFlag::GetMask ( )

GetMask Returns the state of the 16-bit bitmask within this object.

Returns
The state of the 16-bit bitmask

◆ Init()

void Mark3::EventFlag::Init ( )

Init Initializes the EventFlag object prior to use.

◆ operator new()

void* Mark3::EventFlag::operator new ( size_t  sz,
void *  pv 
)
inline

Definition at line 48 of file eventflag.h.

◆ Set()

void Mark3::EventFlag::Set ( uint16_t  u16Mask_)

Set Set additional flags in this object (logical OR). This API can potentially result in threads blocked on Wait() to be unblocked.

Parameters
u16Mask_- Bitmask of flags to set.
Examples:
lab7_events/main.cpp.

◆ Wait() [1/2]

uint16_t Mark3::EventFlag::Wait ( uint16_t  u16Mask_,
EventFlagOperation  eMode_ 
)

Wait Block a thread on the specific flags in this event flag group.

Parameters
u16Mask_- 16-bit bitmask to block on
eMode_- EventFlagOperation::Any_Set: Thread will block on any of the bits in the mask
Returns
Bitmask condition that caused the thread to unblock, or 0 on error or timeout
Examples:
lab7_events/main.cpp.

◆ Wait() [2/2]

uint16_t Mark3::EventFlag::Wait ( uint16_t  u16Mask_,
EventFlagOperation  eMode_,
uint32_t  u32TimeMS_ 
)

Wait Block a thread on the specific flags in this event flag group.

Parameters
u16Mask_- 16-bit bitmask to block on
eMode_- EventFlagOperation::Any_Set: Thread will block on any of the bits in the mask
u32TimeMS_- Time to block (in ms)
Returns
Bitmask condition that caused the thread to unblock, or 0 on error or timeout

◆ Wait_i()

uint16_t Mark3::EventFlag::Wait_i ( uint16_t  u16Mask_,
EventFlagOperation  eMode_,
uint32_t  u32TimeMS_ 
)
private

Wait_i Interal abstraction used to manage both timed and untimed wait operations.

Parameters
u16Mask_- 16-bit bitmask to block on
eMode_- EventFlagOperation::Any_Set: Thread will block on any of the bits in the mask
u32TimeMS_- Time to block (in ms)
Returns
Bitmask condition that caused the thread to unblock, or 0 on error or timeout

◆ WakeMe()

void Mark3::EventFlag::WakeMe ( Thread pclChosenOne_)

WakeMe Wake the given thread, currently blocking on this object.

Parameters
pclChosenOne_Pointer to the owner thread to unblock.

Member Data Documentation

◆ m_u16SetMask

uint16_t Mark3::EventFlag::m_u16SetMask
private

Event flags currently set in this object.

Definition at line 119 of file eventflag.h.


The documentation for this class was generated from the following file: