Limitless queue + fuzzer = lots of ram :)

This commit is contained in:
Eric Severance 2025-01-08 09:46:25 -08:00
parent cf0e59d50d
commit 01417f6fd1
No known key found for this signature in database
GPG Key ID: F19AABB5E1EA1B5F

View File

@ -74,11 +74,17 @@ template <class T> class TypedQueue
{ {
std::queue<T> q; std::queue<T> q;
concurrency::OSThread *reader = NULL; concurrency::OSThread *reader = NULL;
int maxElements;
public: public:
explicit TypedQueue(int maxElements) {} explicit TypedQueue(int _maxElements) : maxElements(_maxElements) {}
int numFree() { return 1; } // Always claim 1 free, because we can grow to any size int numFree()
{
if (maxElements <= 0)
return 1; // Always claim 1 free, because we can grow to any size
return maxElements - numUsed();
}
bool isEmpty() { return q.empty(); } bool isEmpty() { return q.empty(); }
@ -86,6 +92,9 @@ template <class T> class TypedQueue
bool enqueue(T x, TickType_t maxWait = portMAX_DELAY) bool enqueue(T x, TickType_t maxWait = portMAX_DELAY)
{ {
if (numFree() <= 0)
return false;
if (reader) { if (reader) {
reader->setInterval(0); reader->setInterval(0);
concurrency::mainDelay.interrupt(); concurrency::mainDelay.interrupt();
@ -112,4 +121,4 @@ template <class T> class TypedQueue
void setReader(concurrency::OSThread *t) { reader = t; } void setReader(concurrency::OSThread *t) { reader = t; }
}; };
#endif #endif