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

◆ flushN()

fl::size fl::AsyncLogger::flushN ( fl::size maxMessages)

Flush up to N messages from queue (bounded flush)

Parameters
maxMessagesMaximum number of messages to process
Returns
Number of messages actually flushed

Definition at line 122 of file async_logger.cpp.hpp.

122 {
123 fl::size flushed = 0;
124 const char* msg;
125 fl::u16 len;
126
127 // 256-byte stack buffer - handles most messages in a single chunk
128 // Avoids heap allocation entirely by chunking long messages
129 char buffer[256];
130
131 while (flushed < maxMessages && mQueue.tryPop(&msg, &len)) {
132 fl::u16 offset = 0;
133
134 // Process message in chunks to avoid heap allocation
135 while (offset < len) {
136 fl::u16 chunk_size = min(len - offset, static_cast<fl::u16>(sizeof(buffer) - 1));
137 fl::memcpy(buffer, msg + offset, chunk_size);
138 buffer[chunk_size] = '\0'; // Null-terminate
139
140 offset += chunk_size;
141
142 if (offset >= len) {
143 // Last chunk or whole message - use println (adds newline)
144 fl::println(buffer);
145 } else {
146 // Not last chunk - use print (no newline)
147 fl::print(buffer);
148 }
149 }
150
151 mQueue.commit();
152 flushed++;
153 }
154
155 return flushed;
156}
AsyncLogQueue< 128, 4096 > mQueue
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
void print(const char *str) FL_NO_EXCEPT
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
Definition math.h:71
FASTLED_FORCE_INLINE void * memcpy(void *dest, const void *src, size_t n) FL_NO_EXCEPT
Definition cstring.h:136
void println(const char *str) FL_NO_EXCEPT

References fl::FL_NO_EXCEPT, fl::memcpy(), fl::min(), mQueue, offset(), fl::print(), and fl::println().

Referenced by ~AsyncLogger(), fl::async_log_service(), and fl::detail::AsyncLoggerServiceTask::serviceLoggers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: