From a8f93d5f47392aed69e6ddcfd331ecdf9af3896b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 29 Dec 2022 22:42:05 +0100 Subject: [PATCH] Heap Debugging and Thread Disable --- src/concurrency/OSThread.cpp | 14 ++++++++++++++ src/concurrency/OSThread.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/concurrency/OSThread.cpp b/src/concurrency/OSThread.cpp index 88c21d1c5..c5adf297b 100644 --- a/src/concurrency/OSThread.cpp +++ b/src/concurrency/OSThread.cpp @@ -74,8 +74,16 @@ bool OSThread::shouldRun(unsigned long time) void OSThread::run() { +#ifdef DEBUG_HEAP + auto heap = ESP.getFreeHeap(); +#endif currentThread = this; auto newDelay = runOnce(); +#ifdef DEBUG_HEAP + auto newHeap = ESP.getFreeHeap(); + if (newHeap < heap) + DEBUG_MSG("Thread %s leaked heap %d -> %d (%d)\n", ThreadName.c_str(), heap, newHeap, newHeap - heap); +#endif runned(); @@ -85,6 +93,12 @@ void OSThread::run() currentThread = NULL; } +void OSThread::disable() { + enabled = false; + setInterval(INT32_MAX); + +} + /** * This flag is set **only** when setup() starts, to provide a way for us to check for sloppy static constructor calls. * Call assertIsSetup() to force a crash if someone tries to create an instance too early. diff --git a/src/concurrency/OSThread.h b/src/concurrency/OSThread.h index 7a86498b9..f0071c516 100644 --- a/src/concurrency/OSThread.h +++ b/src/concurrency/OSThread.h @@ -53,6 +53,8 @@ class OSThread : public Thread static void setup(); + void disable(); + /** * Wait a specified number msecs starting from the current time (rather than the last time we were run) */