5 #ifndef OS_GENERIC_LOCKLESSPRIORITYQUEUE_HPP 6 #define OS_GENERIC_LOCKLESSPRIORITYQUEUE_HPP 10 #include <type_traits> 13 #include "config/LocklessQueueCfg.hpp" 18 static_assert(std::is_integral<LocklessStateTagType>::value && std::is_unsigned<LocklessStateTagType>::value,
19 "LocklessStateTagType must be an unsigned integral type");
29 template <FwSizeType WIDTH>
31 static constexpr
bool value = ((
sizeof(
unsigned char) == WIDTH) && (ATOMIC_CHAR_LOCK_FREE != 0)) ||
32 ((
sizeof(
unsigned short) == WIDTH) && (ATOMIC_SHORT_LOCK_FREE != 0)) ||
33 ((
sizeof(
unsigned int) == WIDTH) && (ATOMIC_INT_LOCK_FREE != 0)) ||
34 ((
sizeof(
unsigned long) == WIDTH) && (ATOMIC_LONG_LOCK_FREE != 0)) ||
35 ((
sizeof(
unsigned long long) == WIDTH) && (ATOMIC_LLONG_LOCK_FREE != 0));
39 "std::atomic<LocklessStateTagType> is never lock-free on this platform; " 40 "configure a narrower type in config/LocklessQueueCfg.hpp");
41 static_assert(
LocklessAtomicLockFree<
sizeof(U32)>::value,
"std::atomic<U32> is never lock-free on this platform");
43 "std::atomic<FwQueuePriorityType> is never lock-free on this platform");
52 "LOCKLESS_QUEUE_SLOT_ALIGNMENT must be a power of two");
76 static constexpr U32 STATE_BITS = 2;
81 static constexpr U32 TAG_BITS =
static_cast<U32
>(std::numeric_limits<LocklessStateTagType>::digits) - STATE_BITS;
189 U32 candidateSequence,
239 void teardown()
override;
294 FwSizeType getMessagesAvailable()
const override;
299 FwSizeType getMessageHighWaterMark()
const override;
311 #endif // OS_GENERIC_LOCKLESSPRIORITYQUEUE_HPP std::atomic< U32 > m_count
Occupancy count (claimed-or-queued slots) used only for the high-water mark.
PlatformSizeType FwSizeType
std::atomic< U32 > m_available
slot contains no data; available to a producer
Status
status returned from the queue send function
handle for the lockless priority queue
LocklessSlot * m_slots
Pre-allocated array of m_depth slots, aligned within m_slotsAllocation.
consumer has reserved the slot and is draining it
QueueHandle parent class.
constexpr FwSizeType LOCKLESS_QUEUE_SLOT_ALIGNMENT
FwSizeType m_depth
Configured queue depth in messages.
constexpr FwSizeType LOCKLESS_QUEUE_MAX_RETRY_PASSES
std::atomic< FwQueuePriorityType > m_priority
Stored message priority. Atomic because consumers read it during the scan phase.
std::atomic< U32 > m_sequence
LocklessPriorityQueueHandle m_handle
Persistent queue state.
per-slot data for the lockless priority queue
void * m_slotsAllocation
Raw allocation backing m_slots; retained because allocators may ignore alignment. ...
std::atomic< U32 > m_sequence
Sequence assigned to messages on publication for FIFO tiebreak; may wrap (compared modularly)...
std::atomic< LocklessStateTagType > m_stateTag
LocklessSlotState
slot lifecycle states for the lockless priority queue
uint8_t U8
8-bit unsigned integer
producer has reserved the slot and is filling it
PlatformQueuePriorityType FwQueuePriorityType
The type of queue priorities used.
constexpr U32 LOCKLESS_QUEUE_BLOCKING_BACKOFF_US
A read-only abstract superclass for StringBase.
static constexpr bool value
std::atomic< U32 > m_highMark
Maximum value m_count has ever held. Updated by producers via a bounded CAS loop. ...
FwEnumStoreType m_id
Identifier passed to the memory allocator at create() time and reused at teardown().
slot contains a published message available to a consumer
compile-time lock-free possibility for an atomic of unsigned integral width WIDTH ...
U8 * m_data
Pre-allocated array of m_depth * m_messageSize bytes for message payloads.
FwSizeType m_messageSize
Configured maximum size of a single message.
lockless ISR-safe priority queue implementation for Os::QueueInterface