|
ESPHome 2026.1.4
|
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 |
Lock-free task log buffer for host platform.
Threading Model: Multi-Producer Single-Consumer (MPSC)
Only the main loop thread calls get_message_main_loop() and release_message_main_loop()
Producers (multiple threads) Consumer (main loop only) │ │ ▼ ▼ acquire_write_slot_() get_message_main_loop() CAS on reserve_index_ read write_index_ │ check ready flag ▼ │ write to slot (exclusive) ▼ │ read slot data ▼ │ commit_write_slot_() ▼ set ready=true release_message_main_loop() advance write_index_ set ready=false advance read_index_
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:
Definition at line 51 of file task_log_buffer_host.h.
|
explicit |
Constructor that takes the number of message slots.
Definition at line 13 of file task_log_buffer_host.cpp.
| esphome::logger::TaskLogBufferHost::~TaskLogBufferHost | ( | ) |
Definition at line 18 of file task_log_buffer_host.cpp.
| bool esphome::logger::TaskLogBufferHost::get_message_main_loop | ( | LogMessage ** | message | ) |
Definition at line 120 of file task_log_buffer_host.cpp.
|
inline |
Definition at line 92 of file task_log_buffer_host.h.
| void esphome::logger::TaskLogBufferHost::release_message_main_loop | ( | ) |
Definition at line 143 of file task_log_buffer_host.cpp.
| 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.
|
inline |
Definition at line 97 of file task_log_buffer_host.h.
|
staticconstexpr |
Definition at line 54 of file task_log_buffer_host.h.