ESPHome 2026.1.4
Loading...
Searching...
No Matches
esphome::logger::TaskLogBufferLibreTiny Class Reference

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
 

Detailed Description

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:

  • Variable-size messages with header + text stored contiguously (NOSPLIT style)
  • FreeRTOS mutex protects all buffer operations
  • Volatile counter enables fast has_messages() without lock overhead
  • If message doesn't fit at end, padding is added and message wraps to start

Definition at line 43 of file task_log_buffer_libretiny.h.

Constructor & Destructor Documentation

◆ TaskLogBufferLibreTiny()

esphome::logger::TaskLogBufferLibreTiny::TaskLogBufferLibreTiny ( size_t total_buffer_size)
explicit

Definition at line 11 of file task_log_buffer_libretiny.cpp.

◆ ~TaskLogBufferLibreTiny()

esphome::logger::TaskLogBufferLibreTiny::~TaskLogBufferLibreTiny ( )

Definition at line 20 of file task_log_buffer_libretiny.cpp.

Member Function Documentation

◆ borrow_message_main_loop()

bool esphome::logger::TaskLogBufferLibreTiny::borrow_message_main_loop ( LogMessage ** message,
const char ** text )

Definition at line 50 of file task_log_buffer_libretiny.cpp.

◆ has_messages()

bool HOT esphome::logger::TaskLogBufferLibreTiny::has_messages ( ) const
inline

Definition at line 78 of file task_log_buffer_libretiny.h.

◆ release_message_main_loop()

void esphome::logger::TaskLogBufferLibreTiny::release_message_main_loop ( )

Definition at line 88 of file task_log_buffer_libretiny.cpp.

◆ send_message_thread_safe()

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.

◆ size()

size_t esphome::logger::TaskLogBufferLibreTiny::size ( ) const
inline

Definition at line 81 of file task_log_buffer_libretiny.h.

Field Documentation

◆ PADDING_MARKER_LEVEL

uint8_t esphome::logger::TaskLogBufferLibreTiny::PADDING_MARKER_LEVEL = 0xFF
staticconstexpr

Definition at line 60 of file task_log_buffer_libretiny.h.


The documentation for this class was generated from the following files: