2020-07-05 21:11:40 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-09 01:10:44 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "Thread.h"
|
2020-10-09 06:16:51 +00:00
|
|
|
#include "ThreadController.h"
|
2020-10-10 01:57:57 +00:00
|
|
|
#include "concurrency/InterruptableDelay.h"
|
2020-07-05 21:11:40 +00:00
|
|
|
|
2020-09-04 22:03:22 +00:00
|
|
|
namespace concurrency
|
2020-07-05 21:11:40 +00:00
|
|
|
{
|
2020-07-06 19:53:10 +00:00
|
|
|
|
2020-10-09 06:16:51 +00:00
|
|
|
extern ThreadController mainController, timerController;
|
2020-10-10 01:57:57 +00:00
|
|
|
extern InterruptableDelay mainDelay;
|
|
|
|
|
|
|
|
#define RUN_SAME -1
|
2020-10-09 06:16:51 +00:00
|
|
|
|
2020-10-09 01:10:44 +00:00
|
|
|
/**
|
|
|
|
* @brief Base threading
|
2020-10-10 01:57:57 +00:00
|
|
|
*
|
2020-10-11 00:12:53 +00:00
|
|
|
* This is a pseudo threading layer that is super easy to port, well suited to our slow network and very ram & power efficient.
|
2020-10-09 01:10:44 +00:00
|
|
|
*
|
2020-10-11 00:12:53 +00:00
|
|
|
* TODO FIXME @geeksville
|
2020-10-09 06:16:51 +00:00
|
|
|
*
|
2020-10-11 00:12:53 +00:00
|
|
|
* move more things into OSThreads
|
2020-10-09 01:10:44 +00:00
|
|
|
* remove lock/lockguard
|
2020-10-10 01:57:57 +00:00
|
|
|
*
|
|
|
|
* move typedQueue into concurrency
|
|
|
|
* remove freertos from typedqueue
|
2020-10-09 01:10:44 +00:00
|
|
|
*/
|
2020-10-09 06:16:51 +00:00
|
|
|
class OSThread : public Thread
|
2020-10-09 01:10:44 +00:00
|
|
|
{
|
2020-10-09 06:16:51 +00:00
|
|
|
ThreadController *controller;
|
|
|
|
|
2020-10-10 01:57:57 +00:00
|
|
|
/// Show debugging info for disabled threads
|
|
|
|
static bool showDisabled;
|
|
|
|
|
|
|
|
/// Show debugging info for threads when we run them
|
|
|
|
static bool showRun;
|
|
|
|
|
|
|
|
/// Show debugging info for threads we decide not to run;
|
|
|
|
static bool showWaiting;
|
|
|
|
|
2020-10-09 01:10:44 +00:00
|
|
|
public:
|
2020-12-25 07:17:56 +00:00
|
|
|
|
|
|
|
/// For debug printing only (might be null)
|
|
|
|
static const OSThread *currentThread;
|
|
|
|
|
2020-10-09 06:16:51 +00:00
|
|
|
OSThread(const char *name, uint32_t period = 0, ThreadController *controller = &mainController);
|
2020-10-09 01:10:44 +00:00
|
|
|
|
2020-10-09 06:16:51 +00:00
|
|
|
virtual ~OSThread();
|
2020-07-05 21:11:40 +00:00
|
|
|
|
2020-10-10 01:57:57 +00:00
|
|
|
virtual bool shouldRun(unsigned long time);
|
|
|
|
|
2020-10-10 00:28:00 +00:00
|
|
|
static void setup();
|
|
|
|
|
2020-10-10 01:57:57 +00:00
|
|
|
/**
|
|
|
|
* Wait a specified number msecs starting from the current time (rather than the last time we were run)
|
|
|
|
*/
|
|
|
|
void setIntervalFromNow(unsigned long _interval);
|
|
|
|
|
2020-10-09 01:10:44 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* The method that will be called each time our thread gets a chance to run
|
2020-10-09 06:16:51 +00:00
|
|
|
*
|
2020-10-10 01:57:57 +00:00
|
|
|
* Returns desired period for next invocation (or RUN_SAME for no change)
|
2020-10-09 01:10:44 +00:00
|
|
|
*/
|
2020-10-10 01:57:57 +00:00
|
|
|
virtual int32_t runOnce() = 0;
|
2020-10-10 00:28:00 +00:00
|
|
|
|
|
|
|
// Do not override this
|
|
|
|
virtual void run();
|
2020-10-09 01:10:44 +00:00
|
|
|
};
|
2020-07-06 19:53:10 +00:00
|
|
|
|
2020-07-05 21:11:40 +00:00
|
|
|
} // namespace concurrency
|