mirror of
https://github.com/esphome/esphome.git
synced 2025-10-05 19:33:47 +01:00
ble pool
This commit is contained in:
@@ -12,11 +12,11 @@ namespace esp32_ble {
|
|||||||
|
|
||||||
// BLE Event Pool - On-demand pool of BLEEvent objects to avoid heap fragmentation
|
// BLE Event Pool - On-demand pool of BLEEvent objects to avoid heap fragmentation
|
||||||
// Events are allocated on first use and reused thereafter, growing to peak usage
|
// Events are allocated on first use and reused thereafter, growing to peak usage
|
||||||
template<size_t SIZE> class BLEEventPool {
|
template<uint8_t SIZE> class BLEEventPool {
|
||||||
public:
|
public:
|
||||||
BLEEventPool() {
|
BLEEventPool() {
|
||||||
// Initialize all slots as unallocated
|
// Initialize all slots as unallocated
|
||||||
for (size_t i = 0; i < SIZE; i++) {
|
for (uint8_t i = 0; i < SIZE; i++) {
|
||||||
this->events_[i] = nullptr;
|
this->events_[i] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ template<size_t SIZE> class BLEEventPool {
|
|||||||
|
|
||||||
~BLEEventPool() {
|
~BLEEventPool() {
|
||||||
// Delete any events that were created
|
// Delete any events that were created
|
||||||
for (size_t i = 0; i < SIZE; i++) {
|
for (uint8_t i = 0; i < SIZE; i++) {
|
||||||
if (this->events_[i] != nullptr) {
|
if (this->events_[i] != nullptr) {
|
||||||
delete this->events_[i];
|
delete this->events_[i];
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ namespace esp32_ble {
|
|||||||
|
|
||||||
// Lock-free SPSC queue that stores indices instead of pointers
|
// Lock-free SPSC queue that stores indices instead of pointers
|
||||||
// This allows us to use a pre-allocated pool of objects
|
// This allows us to use a pre-allocated pool of objects
|
||||||
template<size_t SIZE> class LockFreeIndexQueue {
|
template<uint8_t SIZE> class LockFreeIndexQueue {
|
||||||
public:
|
public:
|
||||||
static constexpr uint8_t INVALID_INDEX = 0xFF; // 255, which is > MAX_BLE_QUEUE_SIZE (64)
|
static constexpr uint8_t INVALID_INDEX = 0xFF; // 255, which is > MAX_BLE_QUEUE_SIZE (64)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user