SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::sched::PriorityBitmapTraits< BitmapT > Class Template Reference

Operations on the "ready priorities" bitmap used by SwitchStrategyFixedPriority and SwitchStrategyPreemptionThreshold. More...

#include <stk_priority_bitmap.h>

Inheritance diagram for stk::sched::PriorityBitmapTraits< BitmapT >:
Collaboration diagram for stk::sched::PriorityBitmapTraits< BitmapT >:

Public Types

enum  { CAPACITY = (sizeof(BitmapT) * 8U) }

Static Public Member Functions

static __stk_forceinline void Set (BitmapT &bitmap, uint32_t bit)
 Set bit bit.
static __stk_forceinline void Clear (BitmapT &bitmap, uint32_t bit)
 Clear bit bit.
static __stk_forceinline bool IsSet (const BitmapT &bitmap, uint32_t bit)
 Check that bit bit is set.
static __stk_forceinline bool IsEmpty (const BitmapT &bitmap)
 Check that no bit is set.
static __stk_forceinline uint32_t HighestSet (const BitmapT &bitmap)
 Index of the most significant set bit.

Detailed Description

template<class BitmapT>
class stk::sched::PriorityBitmapTraits< BitmapT >

Operations on the "ready priorities" bitmap used by SwitchStrategyFixedPriority and SwitchStrategyPreemptionThreshold.

The primary template supports any unsigned integer type (uint8_t, uint16_t, uint32_t, uint64_t). To support more priority levels than a native integer can hold use stk::sched::PriorityBitmap (96, 128, ..., 1024 priorities, its traits are provided below), or define your own bitmap class and provide a full specialization of this template for it. A specialization must provide:

template <> struct PriorityBitmapTraits<MyBitmap>
{
enum { CAPACITY = 128 }; // number of priority levels the bitmap can hold
static void Set(MyBitmap &b, uint32_t bit); // set bit
static void Clear(MyBitmap &b, uint32_t bit); // clear bit
static bool IsSet(const MyBitmap &b, uint32_t bit); // true if bit is set
static bool IsEmpty(const MyBitmap &b); // true if no bit is set
static uint32_t HighestSet(const MyBitmap &b); // index of the most significant set bit (b is not empty)
};
Operations on the "ready priorities" bitmap used by SwitchStrategyFixedPriority and SwitchStrategyPre...

The bitmap class itself must be default-constructible into the empty state (all bits clear), because the strategy value-initializes it.

Note
All operations run inside the scheduler (critical section), keep them O(1) or as close to it as possible.

Definition at line 84 of file stk_priority_bitmap.h.

Member Enumeration Documentation

◆ anonymous enum

template<class BitmapT>
anonymous enum
Enumerator
CAPACITY 

Definition at line 86 of file stk_priority_bitmap.h.

86{ CAPACITY = (sizeof(BitmapT) * 8U) };

Member Function Documentation

◆ Clear()

template<class BitmapT>
__stk_forceinline void stk::sched::PriorityBitmapTraits< BitmapT >::Clear ( BitmapT & bitmap,
uint32_t bit )
inlinestatic

Clear bit bit.

Definition at line 95 of file stk_priority_bitmap.h.

96 {
97 bitmap = static_cast<BitmapT>(bitmap & static_cast<BitmapT>(~static_cast<BitmapT>(static_cast<BitmapT>(1U) << bit)));
98 }

◆ HighestSet()

template<class BitmapT>
__stk_forceinline uint32_t stk::sched::PriorityBitmapTraits< BitmapT >::HighestSet ( const BitmapT & bitmap)
inlinestatic

Index of the most significant set bit.

Warning
Bitmap must not be empty.

Definition at line 113 of file stk_priority_bitmap.h.

114 {
116 }

◆ IsEmpty()

template<class BitmapT>
__stk_forceinline bool stk::sched::PriorityBitmapTraits< BitmapT >::IsEmpty ( const BitmapT & bitmap)
inlinestatic

◆ IsSet()

template<class BitmapT>
__stk_forceinline bool stk::sched::PriorityBitmapTraits< BitmapT >::IsSet ( const BitmapT & bitmap,
uint32_t bit )
inlinestatic

Check that bit bit is set.

Definition at line 101 of file stk_priority_bitmap.h.

102 {
103 return ((bitmap & static_cast<BitmapT>(static_cast<BitmapT>(1U) << bit)) != static_cast<BitmapT>(0U));
104 }

◆ Set()

template<class BitmapT>
__stk_forceinline void stk::sched::PriorityBitmapTraits< BitmapT >::Set ( BitmapT & bitmap,
uint32_t bit )
inlinestatic

Set bit bit.

Note
The shift is performed in BitmapT width, so it is valid for any bit < CAPACITY.

Definition at line 89 of file stk_priority_bitmap.h.

90 {
91 bitmap = static_cast<BitmapT>(bitmap | static_cast<BitmapT>(static_cast<BitmapT>(1U) << bit));
92 }

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