|
ESPHome 2026.1.4
|
Task log buffer for LibreTiny platform using mutex-protected circular buffer. More...
#include <task_log_buffer_libretiny.h>
Data Structures | |
| struct | LogMessage |
Public Member Functions | |
| TaskLogBufferLibreTiny (size_t total_buffer_size) | |
| ~TaskLogBufferLibreTiny () | |
| bool | borrow_message_main_loop (LogMessage **message, const char **text) |
| void | release_message_main_loop () |
| bool | send_message_thread_safe (uint8_t level, const char *tag, uint16_t line, TaskHandle_t task_handle, const char *format, va_list args) |
| bool HOT | has_messages () const |
| size_t | size () const |
Static Public Attributes | |
| static constexpr uint8_t | PADDING_MARKER_LEVEL = 0xFF |
Task log buffer for LibreTiny platform using mutex-protected circular buffer.
Why This Is Critical: Without thread-safe logging, when a non-main task logs a message, it would directly call the logger which builds a protobuf message in a shared buffer. If this happens while the main loop is also using that buffer (e.g., sending API responses), the buffer gets corrupted, sending garbage to all connected API clients and breaking their connections. This buffer ensures log messages from other tasks are queued safely and processed only from the main loop.
Threading Model: Multi-Producer Single-Consumer (MPSC)
This uses a simple circular buffer protected by a FreeRTOS mutex. Unlike ESP32, LibreTiny lacks hardware atomic support (ARM968E-S has no LDREX/STREX), so we use a volatile counter for fast has_messages() checks instead of atomics.
Design:
Definition at line 43 of file task_log_buffer_libretiny.h.
|
explicit |
Definition at line 11 of file task_log_buffer_libretiny.cpp.
| esphome::logger::TaskLogBufferLibreTiny::~TaskLogBufferLibreTiny | ( | ) |
Definition at line 20 of file task_log_buffer_libretiny.cpp.
| bool esphome::logger::TaskLogBufferLibreTiny::borrow_message_main_loop | ( | LogMessage ** | message, |
| const char ** | text ) |
Definition at line 50 of file task_log_buffer_libretiny.cpp.
|
inline |
Definition at line 78 of file task_log_buffer_libretiny.h.
| void esphome::logger::TaskLogBufferLibreTiny::release_message_main_loop | ( | ) |
Definition at line 88 of file task_log_buffer_libretiny.cpp.
| bool esphome::logger::TaskLogBufferLibreTiny::send_message_thread_safe | ( | uint8_t | level, |
| const char * | tag, | ||
| uint16_t | line, | ||
| TaskHandle_t | task_handle, | ||
| const char * | format, | ||
| va_list | args ) |
Definition at line 103 of file task_log_buffer_libretiny.cpp.
|
inline |
Definition at line 81 of file task_log_buffer_libretiny.h.
|
staticconstexpr |
Definition at line 60 of file task_log_buffer_libretiny.h.