FastLED 3.9.15
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 120 of file async_logger.cpp.hpp.

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

References 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: