Arduino Core 3 (#407)
* Add and remove libs and components for Arduino Core 3 * Arduino Core 3 * Add back Solo1 * Change ESP32-S3 to 4MB build * Update README.md * Fix retain and number of retries * Fix rolling log * Fix defaults * Fix BleScanner on Solo1 * Export settings * Import settings * Fix HA Battery voltage * Change submodule * Update espMqttClient and AsyncTCP * Webserial and MQTT/Network reconnecting * Update nuki_ble --------- Co-authored-by: iranl <iranl@github.com>
This commit is contained in:
@@ -9,7 +9,12 @@ the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <new> // new (std::nothrow)
|
||||
#if EMC_USE_MEMPOOL
|
||||
#include "MemoryPool/src/MemoryPool.h"
|
||||
#include "Config.h"
|
||||
#else
|
||||
#include <new> // new (std::nothrow)
|
||||
#endif
|
||||
#include <utility> // std::forward
|
||||
|
||||
namespace espMqttClientInternals {
|
||||
@@ -28,11 +33,20 @@ class Outbox {
|
||||
: _first(nullptr)
|
||||
, _last(nullptr)
|
||||
, _current(nullptr)
|
||||
, _prev(nullptr) {}
|
||||
, _prev(nullptr)
|
||||
#if EMC_USE_MEMPOOL
|
||||
, _memPool()
|
||||
#endif
|
||||
{}
|
||||
~Outbox() {
|
||||
while (_first) {
|
||||
Node* n = _first->next;
|
||||
#if EMC_USE_MEMPOOL
|
||||
_first->~Node();
|
||||
_memPool.free(_first);
|
||||
#else
|
||||
delete _first;
|
||||
#endif
|
||||
_first = n;
|
||||
}
|
||||
}
|
||||
@@ -79,7 +93,15 @@ class Outbox {
|
||||
template <class... Args>
|
||||
Iterator emplace(Args&&... args) {
|
||||
Iterator it;
|
||||
Node* node = new (std::nothrow) Node(std::forward<Args>(args) ...);
|
||||
#if EMC_USE_MEMPOOL
|
||||
void* buf = _memPool.malloc();
|
||||
Node* node = nullptr;
|
||||
if (buf) {
|
||||
node = new(buf) Node(std::forward<Args>(args) ...);
|
||||
}
|
||||
#else
|
||||
Node* node = new(std::nothrow) Node(std::forward<Args>(args) ...);
|
||||
#endif
|
||||
if (node != nullptr) {
|
||||
if (!_first) {
|
||||
// queue is empty
|
||||
@@ -103,7 +125,15 @@ class Outbox {
|
||||
template <class... Args>
|
||||
Iterator emplaceFront(Args&&... args) {
|
||||
Iterator it;
|
||||
Node* node = new (std::nothrow) Node(std::forward<Args>(args) ...);
|
||||
#if EMC_USE_MEMPOOL
|
||||
void* buf = _memPool.malloc();
|
||||
Node* node = nullptr;
|
||||
if (buf) {
|
||||
node = new(buf) Node(std::forward<Args>(args) ...);
|
||||
}
|
||||
#else
|
||||
Node* node = new(std::nothrow) Node(std::forward<Args>(args) ...);
|
||||
#endif
|
||||
if (node != nullptr) {
|
||||
if (!_first) {
|
||||
// queue is empty
|
||||
@@ -178,6 +208,9 @@ class Outbox {
|
||||
Node* _last;
|
||||
Node* _current;
|
||||
Node* _prev; // element just before _current
|
||||
#if EMC_USE_MEMPOOL
|
||||
MemoryPool::Fixed<EMC_NUM_POOL_ELEMENTS, sizeof(Node)> _memPool;
|
||||
#endif
|
||||
|
||||
void _remove(Node* prev, Node* node) {
|
||||
if (!node) return;
|
||||
@@ -210,7 +243,12 @@ class Outbox {
|
||||
}
|
||||
|
||||
// finally, delete the node
|
||||
delete node;
|
||||
#if EMC_USE_MEMPOOL
|
||||
node->~Node();
|
||||
_memPool.free(node);
|
||||
#else
|
||||
delete node;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user