FastLED 3.10.8
Loading...
Searching...
No Matches
async_log_queue.h
Go to the documentation of this file.
1#pragma once
2
5
6#include "fl/stl/int.h"
7#include "fl/stl/noexcept.h"
9
10namespace fl {
11
12class string;
13
17template <fl::size DescriptorCount = 128, fl::size ArenaSize = 4096>
19 // Compile-time assertions for power-of-2 sizes (enables cheap modulo with &)
20 FL_STATIC_ASSERT((DescriptorCount & (DescriptorCount - 1)) == 0,
21 "DescriptorCount must be power of 2");
22 FL_STATIC_ASSERT((ArenaSize & (ArenaSize - 1)) == 0,
23 "ArenaSize must be power of 2");
24 FL_STATIC_ASSERT(DescriptorCount >= 4, "DescriptorCount must be >= 4");
25 FL_STATIC_ASSERT(ArenaSize >= 32, "ArenaSize must be >= 32");
26
27public:
29 enum { MAX_MESSAGE_LENGTH = 512 };
30
32 struct Descriptor {
33 fl::u32 mStartIdx;
34 fl::u16 mLength;
35 fl::u16 mPadding;
36
38 };
39
41
43 bool push(const fl::string& msg) FL_NO_EXCEPT;
44
46 bool push(const char* str) FL_NO_EXCEPT;
47
49 bool tryPop(const char** outPtr, fl::u16* outLen) FL_NO_EXCEPT;
50
52 void commit() FL_NO_EXCEPT;
53
55 fl::u32 droppedCount() const FL_NO_EXCEPT;
56
58 fl::size size() const FL_NO_EXCEPT;
59
61 bool empty() const FL_NO_EXCEPT;
62
65 return DescriptorCount - 1; // One slot reserved for full/empty distinction
66 }
67
68private:
70 bool push(const char* str, fl::u16 len) FL_NO_EXCEPT;
71 static fl::u16 boundedStrlen(const char* str, fl::u16 maxLen) FL_NO_EXCEPT;
72 bool arenaHasSpace(fl::u32 aHead, fl::u32 aTail, fl::u16 len) const FL_NO_EXCEPT;
73 fl::u32 loadHead() const FL_NO_EXCEPT;
74 fl::u32 loadTail() const FL_NO_EXCEPT;
75 fl::u32 loadArenaTail() const FL_NO_EXCEPT;
77
78 // Member variables
79 Descriptor mDescriptors[DescriptorCount];
80 char mArena[ArenaSize];
81
82 // Ring indices (modified under critical section for memory ordering)
83 volatile fl::u32 mHead;
84 volatile fl::u32 mTail;
85 volatile fl::u32 mArenaHead;
86 volatile fl::u32 mArenaTail;
87
88 volatile fl::u32 mDropped;
89};
90
91} // namespace fl
fl::size size() const FL_NO_EXCEPT
Get current number of messages in queue.
bool push(const fl::string &msg) FL_NO_EXCEPT
Push a message from fl::string (ISR-safe)
static fl::u16 boundedStrlen(const char *str, fl::u16 maxLen) FL_NO_EXCEPT
AsyncLogQueue() FL_NO_EXCEPT
bool arenaHasSpace(fl::u32 aHead, fl::u32 aTail, fl::u16 len) const FL_NO_EXCEPT
FL_STATIC_ASSERT(ArenaSize >=32, "ArenaSize must be >= 32")
volatile fl::u32 mArenaHead
Producer write position (arena)
bool tryPop(const char **outPtr, fl::u16 *outLen) FL_NO_EXCEPT
Consumer: Try to pop one message (main thread only)
volatile fl::u32 mTail
Consumer read position (descriptor ring)
fl::u32 droppedCount() const FL_NO_EXCEPT
Get number of messages dropped due to overflow.
fl::u32 loadArenaTail() const FL_NO_EXCEPT
volatile fl::u32 mDropped
Count of dropped messages (overflow)
FL_STATIC_ASSERT((DescriptorCount &(DescriptorCount - 1))==0, "DescriptorCount must be power of 2")
FL_STATIC_ASSERT(DescriptorCount >=4, "DescriptorCount must be >= 4")
void atomicIncDropped() FL_NO_EXCEPT
fl::u32 loadHead() const FL_NO_EXCEPT
bool empty() const FL_NO_EXCEPT
Check if queue is empty.
fl::u32 loadTail() const FL_NO_EXCEPT
constexpr fl::size capacity() const FL_NO_EXCEPT
Get maximum descriptor capacity.
FL_STATIC_ASSERT((ArenaSize &(ArenaSize - 1))==0, "ArenaSize must be power of 2")
void commit() FL_NO_EXCEPT
Consumer: Commit the popped message to free space (main thread only)
Descriptor mDescriptors[DescriptorCount]
Ring of message descriptors.
volatile fl::u32 mHead
Producer write position (descriptor ring)
volatile fl::u32 mArenaTail
Consumer read position (arena)
char mArena[ArenaSize]
String storage arena.
#define constexpr
Declares that it is possible to evaluate a value at compile time, introduced in C++11.
Definition cpp_compat.h:15
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Portable compile-time assertion wrapper.
fl::u32 mStartIdx
Offset into arena where message starts.
fl::u16 mLength
Length of message in bytes.
fl::u16 mPadding
Reserved for alignment (unused)
Descriptor for one log message.