mirror of
https://github.com/esphome/esphome.git
synced 2025-10-05 11:23:47 +01:00
ble pool
This commit is contained in:
@@ -30,8 +30,9 @@ template<uint8_t SIZE> class BLEEventPool {
|
|||||||
BLEEvent *allocate() {
|
BLEEvent *allocate() {
|
||||||
// Try to get from free list first
|
// Try to get from free list first
|
||||||
BLEEvent *event = this->free_list_.pop();
|
BLEEvent *event = this->free_list_.pop();
|
||||||
|
if (event != nullptr)
|
||||||
|
return event;
|
||||||
|
|
||||||
if (event == nullptr) {
|
|
||||||
// Need to create a new event
|
// Need to create a new event
|
||||||
if (this->total_created_ >= SIZE) {
|
if (this->total_created_ >= SIZE) {
|
||||||
// Pool is at capacity
|
// Pool is at capacity
|
||||||
@@ -50,8 +51,6 @@ template<uint8_t SIZE> class BLEEventPool {
|
|||||||
// Placement new to construct the object
|
// Placement new to construct the object
|
||||||
new (event) BLEEvent();
|
new (event) BLEEvent();
|
||||||
this->total_created_.fetch_add(1, std::memory_order_relaxed);
|
this->total_created_.fetch_add(1, std::memory_order_relaxed);
|
||||||
}
|
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user