MCPcopy Create free account
hub / github.com/FastLED/FastLED / flushN

Method flushN

src/fl/log/async_logger.cpp.hpp:120–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120fl::size AsyncLogger::flushN(fl::size maxMessages) {
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}
155
156bool AsyncLogger::enableBackgroundFlush(fl::u32 interval_ms, fl::size messages_per_tick) {
157 detail::BackgroundFlushState& state = Singleton<detail::BackgroundFlushState>::instance();

Callers 4

async_log_serviceFunction · 0.80
serviceLoggersMethod · 0.80
async_logger.hppFile · 0.80

Calls 5

tryPopMethod · 0.80
commitMethod · 0.80
memcpyFunction · 0.50
printlnFunction · 0.50
printFunction · 0.50

Tested by

no test coverage detected