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-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-09 01:10:44 +00:00
|
|
|
/**
|
|
|
|
* @brief Base threading
|
|
|
|
*
|
|
|
|
* TODO FIXME @geeksville
|
|
|
|
* basic functionality
|
|
|
|
* sleeping the correct amount of time in main
|
|
|
|
* NotifiedWorkerThread set/clears enabled
|
|
|
|
*
|
2020-10-09 06:16:51 +00:00
|
|
|
* notifyLater should start now - not relative to last start time
|
|
|
|
* clear notification before calling handler
|
|
|
|
*
|
2020-10-09 01:10:44 +00:00
|
|
|
* stopping sleep instantly as soon as an event occurs.
|
|
|
|
* use global functions delayTillWakeEvent(time), doWakeEvent(isInISR) - use freertos mutex or somesuch
|
|
|
|
*
|
2020-10-10 00:28:00 +00:00
|
|
|
* make everything use osthread
|
|
|
|
*
|
|
|
|
* Debug what is keeping us from sleeping
|
|
|
|
*
|
2020-10-09 06:16:51 +00:00
|
|
|
* have router thread block on its message queue in runOnce
|
|
|
|
*
|
2020-10-09 01:10:44 +00:00
|
|
|
* remove lock/lockguard
|
|
|
|
*/
|
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-09 01:10:44 +00:00
|
|
|
public:
|
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 00:28:00 +00:00
|
|
|
static void setup();
|
|
|
|
|
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
|
|
|
*
|
|
|
|
* Returns desired period for next invocation (or 0 for no change)
|
2020-10-09 01:10:44 +00:00
|
|
|
*/
|
2020-10-09 06:16:51 +00:00
|
|
|
virtual uint32_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
|