FastLED 3.9.15
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 117 of file async_log_queue.cpp.hpp.

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

+ Here is the call graph for this function: