mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
[core] add ring buffer destructor (#7500)
This commit is contained in:
parent
21fbbc5fb9
commit
3b1b1071f1
2 changed files with 15 additions and 2 deletions
|
@ -11,16 +11,26 @@ namespace esphome {
|
|||
|
||||
static const char *const TAG = "ring_buffer";
|
||||
|
||||
RingBuffer::~RingBuffer() {
|
||||
if (this->handle_ != nullptr) {
|
||||
vStreamBufferDelete(this->handle_);
|
||||
ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
allocator.deallocate(this->storage_, this->size_);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<RingBuffer> RingBuffer::create(size_t len) {
|
||||
std::unique_ptr<RingBuffer> rb = make_unique<RingBuffer>();
|
||||
|
||||
rb->size_ = len + 1;
|
||||
|
||||
ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||
rb->storage_ = allocator.allocate(len + 1);
|
||||
rb->storage_ = allocator.allocate(rb->size_);
|
||||
if (rb->storage_ == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rb->handle_ = xStreamBufferCreateStatic(len + 1, 1, rb->storage_, &rb->structure_);
|
||||
rb->handle_ = xStreamBufferCreateStatic(rb->size_, 1, rb->storage_, &rb->structure_);
|
||||
ESP_LOGD(TAG, "Created ring buffer with size %u", len);
|
||||
return rb;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ namespace esphome {
|
|||
|
||||
class RingBuffer {
|
||||
public:
|
||||
~RingBuffer();
|
||||
|
||||
/**
|
||||
* @brief Reads from the ring buffer, waiting up to a specified number of ticks if necessary.
|
||||
*
|
||||
|
@ -83,6 +85,7 @@ class RingBuffer {
|
|||
StreamBufferHandle_t handle_;
|
||||
StaticStreamBuffer_t structure_;
|
||||
uint8_t *storage_;
|
||||
size_t size_{0};
|
||||
};
|
||||
|
||||
} // namespace esphome
|
||||
|
|
Loading…
Reference in a new issue