add assertIsSetup() and use it from OSThread constructor

fixes nasty bug @mc-hamster discovered with plugin order of operations
This commit is contained in:
Kevin Hester
2021-01-08 13:15:49 +08:00
parent 3636b87db0
commit 7aacfd66ef
16 changed files with 108 additions and 28 deletions

View File

@@ -17,14 +17,14 @@ extern InterruptableDelay mainDelay;
/**
* @brief Base threading
*
*
* This is a pseudo threading layer that is super easy to port, well suited to our slow network and very ram & power efficient.
*
* TODO FIXME @geeksville
*
* move more things into OSThreads
* remove lock/lockguard
*
*
* move typedQueue into concurrency
* remove freertos from typedqueue
*/
@@ -42,7 +42,6 @@ class OSThread : public Thread
static bool showWaiting;
public:
/// For debug printing only (might be null)
static const OSThread *currentThread;
@@ -71,4 +70,19 @@ class OSThread : public Thread
virtual void run();
};
/**
* 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.
*
* it is super important to never allocate those object statically. instead, you should explicitly
* new them at a point where you are guaranteed that other objects that this instance
* depends on have already been created.
*
* in particular, for OSThread that means "all instances must be declared via new() in setup() or later" -
* this makes it guaranteed that the global mainController is fully constructed first.
*/
extern bool hasBeenSetup;
void assertIsSetup();
} // namespace concurrency