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

Lock-free task log buffer for host platform. More...

#include <task_log_buffer_host.h>

Data Structures

struct  LogMessage
 

Public Member Functions

 TaskLogBufferHost (size_t slot_count)
 Constructor that takes the number of message slots.
 
 ~TaskLogBufferHost ()
 
bool get_message_main_loop (LogMessage **message)
 
void release_message_main_loop ()
 
bool send_message_thread_safe (uint8_t level, const char *tag, uint16_t line, const char *format, va_list args)
 
bool HOT has_messages () const
 
size_t size () const
 

Static Public Attributes

static constexpr size_t DEFAULT_SLOT_COUNT = 64
 

Detailed Description

Lock-free task log buffer for host platform.

Threading Model: Multi-Producer Single-Consumer (MPSC)

This implements a lock-free ring buffer for log messages on the host platform. It uses atomic compare-and-swap (CAS) operations for thread-safe slot reservation without requiring mutexes in the hot path.

Design:

  • Fixed number of pre-allocated message slots to avoid dynamic allocation
  • Each slot contains a header and fixed-size text buffer
  • Atomic CAS for slot reservation allows multiple producers without locks
  • Single consumer (main loop) processes messages in order

Definition at line 51 of file task_log_buffer_host.h.

Constructor & Destructor Documentation

◆ TaskLogBufferHost()

esphome::logger::TaskLogBufferHost::TaskLogBufferHost ( size_t slot_count)
explicit

Constructor that takes the number of message slots.

Definition at line 13 of file task_log_buffer_host.cpp.

◆ ~TaskLogBufferHost()

esphome::logger::TaskLogBufferHost::~TaskLogBufferHost ( )

Definition at line 18 of file task_log_buffer_host.cpp.

Member Function Documentation

◆ get_message_main_loop()

bool esphome::logger::TaskLogBufferHost::get_message_main_loop ( LogMessage ** message)

Definition at line 120 of file task_log_buffer_host.cpp.

◆ has_messages()

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

Definition at line 92 of file task_log_buffer_host.h.

◆ release_message_main_loop()

void esphome::logger::TaskLogBufferHost::release_message_main_loop ( )

Definition at line 143 of file task_log_buffer_host.cpp.

◆ send_message_thread_safe()

bool esphome::logger::TaskLogBufferHost::send_message_thread_safe ( uint8_t level,
const char * tag,
uint16_t line,
const char * format,
va_list args )

Definition at line 73 of file task_log_buffer_host.cpp.

◆ size()

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

Definition at line 97 of file task_log_buffer_host.h.

Field Documentation

◆ DEFAULT_SLOT_COUNT

size_t esphome::logger::TaskLogBufferHost::DEFAULT_SLOT_COUNT = 64
staticconstexpr

Definition at line 54 of file task_log_buffer_host.h.


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