[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:
J. Nick Koston
2026-03-17 11:58:47 -10:00
parent bba11b3b1e
commit 8acc033873
+7
View File
@@ -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) {}