Skip to content

Commit

Permalink
we don't use the static MemoryPool anywhere, ditch dead code.
Browse files Browse the repository at this point in the history
  • Loading branch information
caveman99 committed Dec 11, 2023
1 parent dc309f6 commit 385b29c
Showing 1 changed file with 0 additions and 55 deletions.
55 changes: 0 additions & 55 deletions src/mesh/MemoryPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,58 +73,3 @@ template <class T> class MemoryDynamic : public Allocator<T>
return p;
}
};

/**
* A pool based allocator
*
*/
template <class T> class MemoryPool : public Allocator<T>
{
PointerQueue<T> dead;

T *buf; // our large raw block of memory

size_t maxElements;

public:
explicit MemoryPool(size_t _maxElements) : dead(_maxElements), maxElements(_maxElements)
{
buf = new T[maxElements];

// prefill dead
for (size_t i = 0; i < maxElements; i++)
release(&buf[i]);
}

~MemoryPool() { delete[] buf; }

/// Return a buffer for use by others
void release(T *p)
{
assert(p >= buf &&
(size_t)(p - buf) <
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
assert(dead.enqueue(p, 0));
}

#ifdef HAS_FREE_RTOS
/// Return a buffer from an ISR, if higherPriWoken is set to true you have some work to do ;-)
void releaseFromISR(T *p, BaseType_t *higherPriWoken)
{
assert(p >= buf &&
(size_t)(p - buf) <
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
assert(dead.enqueueFromISR(p, higherPriWoken));
}
#endif

protected:
/// Return a queable object which has been prefilled with zeros - allow timeout to wait for available buffers (you
/// probably don't want this version).
virtual T *alloc(TickType_t maxWait)
{
T *p = dead.dequeuePtr(maxWait);
assert(p);
return p;
}
};

0 comments on commit 385b29c

Please sign in to comment.