10#ifndef STK_PRIORITY_BITMAP_H_
11#define STK_PRIORITY_BITMAP_H_
50template <
class BitmapT>
54namespace priority_bitmap_detail {
73 const uint32_t hi =
static_cast<uint32_t
>(value >> 32U);
83template <
class BitmapT>
91 bitmap =
static_cast<BitmapT
>(bitmap |
static_cast<BitmapT
>(
static_cast<BitmapT
>(1U) << bit));
97 bitmap =
static_cast<BitmapT
>(bitmap &
static_cast<BitmapT
>(~static_cast<BitmapT>(
static_cast<BitmapT
>(1U) << bit)));
103 return ((bitmap &
static_cast<BitmapT
>(
static_cast<BitmapT
>(1U) << bit)) !=
static_cast<BitmapT
>(0U));
109 return (bitmap ==
static_cast<BitmapT
>(0U));
115 return priority_bitmap_detail::Scan<
sizeof(BitmapT)>::Highest(bitmap);
139template <u
int32_t BITS>
162 const uint32_t word = (bit >> 5U);
164 m_words[word] |= (1U << (bit & 31U));
173 const uint32_t word = (bit >> 5U);
175 m_words[word] &= ~(1U << (bit & 31U));
188 return ((
m_words[bit >> 5U] & (1U << (bit & 31U))) != 0U);
215template <u
int32_t BITS>
232 return bitmap.IsSet(bit);
237 return bitmap.IsEmpty();
242 return bitmap.HighestSet();
253template <u
int16_t MAX_PRIORITIES, u
int32_t KIND = ((MAX_PRIORITIES <= 32U) ? 0U : ((MAX_PRIORITIES <= 64U) ? 1U : 2U))>
254struct ReadyBitmapSelect
256 typedef PriorityBitmap<(((MAX_PRIORITIES + 31U) / 32U) * 32U)> Type;
260template <u
int16_t MAX_PRIORITIES>
263 typedef uint32_t
Type;
266template <u
int16_t MAX_PRIORITIES>
269 typedef uint64_t
Type;
Contains interface definitions of the library.
#define __stk_forceinline
Forces compiler to always inline the decorated function, regardless of optimisation level.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Namespace of STK package.
uint32_t CountLeadingZeros(const uint32_t value) noexcept
Count leading zeros.
Task-switching strategies (stk::sched::SwitchStrategy*) and their helpers (priority bitmaps,...
Operations on the "ready priorities" bitmap used by SwitchStrategyFixedPriority and SwitchStrategyPre...
static __stk_forceinline void Set(BitmapT &bitmap, uint32_t bit)
Set bit bit.
static __stk_forceinline uint32_t HighestSet(const BitmapT &bitmap)
Index of the most significant set bit.
static __stk_forceinline void Clear(BitmapT &bitmap, uint32_t bit)
Clear bit bit.
static __stk_forceinline bool IsEmpty(const BitmapT &bitmap)
Check that no bit is set.
static __stk_forceinline bool IsSet(const BitmapT &bitmap, uint32_t bit)
Check that bit bit is set.
Two-level bitmap for more priority levels than a native integer can hold (BITS is a multiple of 32 ab...
__stk_forceinline bool IsEmpty() const
Check that no bit is set.
__stk_forceinline bool IsSet(uint32_t bit) const
Check that bit bit is set, [0, BITS).
STK_STATIC_ASSERT_DESC_N(Max1024, BITS<=1024U, "PriorityBitmap: BITS must not exceed 1024 (32-bit summary)")
STK_STATIC_ASSERT_DESC_N(Multiple32,(BITS % 32U)==0U, "PriorityBitmap: BITS must be a multiple of 32")
__stk_forceinline void Set(uint32_t bit)
Set bit bit, [0, BITS).
__stk_forceinline void Clear(uint32_t bit)
Clear bit bit, [0, BITS).
PriorityBitmap()
Construct an empty bitmap.
STK_STATIC_ASSERT_DESC_N(Min32, BITS >=32U, "PriorityBitmap: BITS must be at least 32")
__stk_forceinline uint32_t HighestSet() const
Index of the most significant set bit.
Selects the default bitmap type for a number of priority levels: uint32_t for up to 32,...
PriorityBitmap<(((MAX_PRIORITIES+31U)/32U) *32U)> Type