firmware/src/concurrency/OSThread.h

51 lines
1.2 KiB
C
Raw Normal View History

#pragma once
2020-10-09 01:10:44 +00:00
#include <cstdlib>
#include <stdint.h>
#include "Thread.h"
#include "ThreadController.h"
2020-09-04 22:03:22 +00:00
namespace concurrency
{
2020-07-06 19:53:10 +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
*
* 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
*
* have router thread block on its message queue in runOnce
*
2020-10-09 01:10:44 +00:00
* remove lock/lockguard
*/
class OSThread : public Thread
2020-10-09 01:10:44 +00:00
{
ThreadController *controller;
2020-10-09 01:10:44 +00:00
public:
OSThread(const char *name, uint32_t period = 0, ThreadController *controller = &mainController);
2020-10-09 01:10:44 +00:00
virtual ~OSThread();
2020-10-09 01:10:44 +00:00
protected:
/**
* The method that will be called each time our thread gets a chance to run
*
* Returns desired period for next invocation (or 0 for no change)
2020-10-09 01:10:44 +00:00
*/
virtual uint32_t runOnce() = 0;
2020-10-09 01:10:44 +00:00
};
2020-07-06 19:53:10 +00:00
} // namespace concurrency