mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 23:37:34 +00:00
[core] Document EventPool sizing requirement with LockFreeQueue
Add a comment to EventPool documenting that when paired with a LockFreeQueue<T, N>, the pool should be sized to N-1 (the queue's actual capacity) to prevent slot leaks and SPSC violations.
This commit is contained in:
@@ -13,6 +13,13 @@ namespace esphome {
|
||||
// Events are allocated on first use and reused thereafter, growing to peak usage
|
||||
// @tparam T The type of objects managed by the pool (must have a release() method)
|
||||
// @tparam SIZE The maximum number of objects in the pool (1-255, limited by uint8_t)
|
||||
//
|
||||
// SIZING: When paired with a LockFreeQueue<T, Q_SIZE>, the pool SIZE should be
|
||||
// Q_SIZE - 1 (the queue's actual capacity, since the ring buffer reserves one slot).
|
||||
// This ensures allocate() returns nullptr before push() can fail, which:
|
||||
// - Prevents permanently leaking a pool slot
|
||||
// - Avoids needing release() on the producer path after a failed push(),
|
||||
// preserving the SPSC contract on the internal free list
|
||||
template<class T, uint8_t SIZE> class EventPool {
|
||||
public:
|
||||
EventPool() : total_created_(0) {}
|
||||
|
||||
Reference in New Issue
Block a user