[logger] Move task log buffer storage to BSS (#15153)
This commit is contained in:
1 parent
26e78c840c
commit
690dc324c9
15 files changed
+69
-127
No files matched your search
@@ -1,19 +1,15 @@
|
||||
#ifdef USE_LIBRETINY
|
||||
|
||||
#include "task_log_buffer_libretiny.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#ifdef USE_ESPHOME_TASK_LOG_BUFFER
|
||||
|
||||
namespace esphome::logger {
|
||||
|
||||
TaskLogBuffer::TaskLogBuffer(size_t total_buffer_size) {
|
||||
this->size_ = total_buffer_size;
|
||||
// Allocate memory for the circular buffer using ESPHome's RAM allocator
|
||||
RAMAllocator<uint8_t> allocator;
|
||||
this->storage_ = allocator.allocate(this->size_);
|
||||
TaskLogBuffer::TaskLogBuffer() {
|
||||
// Create mutex for thread-safe access
|
||||
// Storage is a member array (embedded in Logger), no heap allocation needed
|
||||
this->mutex_ = xSemaphoreCreateMutex();
|
||||
}
|
||||
|
||||
@@ -22,11 +18,6 @@ TaskLogBuffer::~TaskLogBuffer() {
|
||||
vSemaphoreDelete(this->mutex_);
|
||||
this->mutex_ = nullptr;
|
||||
}
|
||||
if (this->storage_ != nullptr) {
|
||||
RAMAllocator<uint8_t> allocator;
|
||||
allocator.deallocate(this->storage_, this->size_);
|
||||
this->storage_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
size_t TaskLogBuffer::available_contiguous_space() const {
|
||||
@@ -34,7 +25,7 @@ size_t TaskLogBuffer::available_contiguous_space() const {
|
||||
// head is ahead of or equal to tail
|
||||
// Available space is from head to end, plus from start to tail
|
||||
// But for contiguous, just from head to end (minus 1 to avoid head==tail ambiguity)
|
||||
size_t space_to_end = this->size_ - this->head_;
|
||||
size_t space_to_end = ESPHOME_TASK_LOG_BUFFER_SIZE - this->head_;
|
||||
if (this->tail_ == 0) {
|
||||
// Can't use the last byte or head would equal tail
|
||||
return space_to_end > 0 ? space_to_end - 1 : 0;
|
||||
@@ -48,8 +39,8 @@ size_t TaskLogBuffer::available_contiguous_space() const {
|
||||
}
|
||||
|
||||
bool TaskLogBuffer::borrow_message_main_loop(LogMessage *&message, uint16_t &text_length) {
|
||||
// Check if buffer was initialized successfully
|
||||
if (this->mutex_ == nullptr || this->storage_ == nullptr) {
|
||||
// Check if mutex was initialized successfully
|
||||
if (this->mutex_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -86,7 +77,7 @@ void TaskLogBuffer::release_message_main_loop() {
|
||||
this->tail_ += this->current_message_size_;
|
||||
|
||||
// Handle wrap-around if we've reached the end
|
||||
if (this->tail_ >= this->size_) {
|
||||
if (this->tail_ >= ESPHOME_TASK_LOG_BUFFER_SIZE) {
|
||||
this->tail_ = 0;
|
||||
}
|
||||
|
||||
@@ -115,9 +106,9 @@ bool TaskLogBuffer::send_message_thread_safe(uint8_t level, const char *tag, uin
|
||||
// Calculate total size needed (header + text length + null terminator)
|
||||
size_t total_size = message_total_size(text_length);
|
||||
|
||||
// Check if buffer was initialized successfully
|
||||
if (this->mutex_ == nullptr || this->storage_ == nullptr) {
|
||||
return false; // Buffer not initialized, fall back to direct output
|
||||
// Check if mutex was initialized successfully
|
||||
if (this->mutex_ == nullptr) {
|
||||
return false; // Mutex not initialized, fall back to direct output
|
||||
}
|
||||
|
||||
// Try to acquire mutex without blocking - don't block logging tasks
|
||||
@@ -185,7 +176,7 @@ bool TaskLogBuffer::send_message_thread_safe(uint8_t level, const char *tag, uin
|
||||
this->head_ += total_size;
|
||||
|
||||
// Handle wrap-around (shouldn't happen due to contiguous space check, but be safe)
|
||||
if (this->head_ >= this->size_) {
|
||||
if (this->head_ >= ESPHOME_TASK_LOG_BUFFER_SIZE) {
|
||||
this->head_ = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user