FastLED 3.10.8
Loading...
Searching...
No Matches

◆ push() [2/3]

template<fl::size DescriptorCount, fl::size ArenaSize>
bool fl::AsyncLogQueue< DescriptorCount, ArenaSize >::push ( const char * str,
fl::u16 len )
private

Implementation details.

Definition at line 118 of file async_log_queue.cpp.hpp.

118 {
119 if (len == 0) {
120 return true; // Empty message, accept but don't store
121 }
122
123 // Load indices (head is producer-owned, tail needs barrier)
126 fl::u32 next = (head + 1) & (DescriptorCount - 1);
127
128 // Check if descriptor ring is full
129 if (next == tail) {
131 return false;
132 }
133
134 // Check if arena has enough free space
137
138 if (!arenaHasSpace(aHead, aTail, len)) {
140 return false;
141 }
142
143 // Allocate space in arena
145
146 // Check if message would wrap past arena end
147 if (start + len > ArenaSize) {
148 // Insert padding to wrap to start of arena (contiguous records)
150
151 // Check if padding + message fits
152 if (!arenaHasSpace(aHead, aTail, static_cast<fl::u16>(padding + len))) {
154 return false;
155 }
156
157 // Advance arena head to skip padding bytes
158 aHead = (aHead + padding) & (ArenaSize - 1); // Should wrap to 0
159 // Store message at wrapped position
160 start = aHead;
161 }
162
163 // Copy message into arena (the only potentially slow operation in ISR)
164 for (fl::u16 i = 0; i < len; i++) {
165 mArena[start + i] = str[i];
166 }
167
168 // Advance arena head by message length
169 fl::u32 newArenaHead = (aHead + len) & (ArenaSize - 1);
170 {
171 fl::isr::critical_section cs; // Protect arena head update
173 }
174
175 // Write descriptor (data is already copied, safe to publish)
176 mDescriptors[head].mStartIdx = start;
177 mDescriptors[head].mLength = len;
178
179 // Publish by advancing head (critical section for memory ordering)
180 {
182 mHead = next;
183 }
184
185 return true;
186}
bool arenaHasSpace(fl::u32 aHead, fl::u32 aTail, fl::u16 len) const FL_NO_EXCEPT
volatile fl::u32 mArenaHead
Producer write position (arena)
fl::u32 loadArenaTail() const FL_NO_EXCEPT
void atomicIncDropped() FL_NO_EXCEPT
fl::u32 loadTail() const FL_NO_EXCEPT
Descriptor mDescriptors[DescriptorCount]
Ring of message descriptors.
volatile fl::u32 mHead
Producer write position (descriptor ring)
char mArena[ArenaSize]
String storage arena.
High-performance SPSC async log queue.

References arenaHasSpace(), atomicIncDropped(), fl::FL_NO_EXCEPT, loadArenaTail(), loadTail(), mArena, mArenaHead, mDescriptors, and mHead.

+ Here is the call graph for this function: