Files
firmware/src/concurrency/NotifiedWorkerThread.h

46 lines
979 B
C
Raw Normal View History

#pragma once
#include "OSThread.h"
namespace concurrency
{
2020-10-09 09:10:44 +08:00
/**
* @brief A worker thread that waits on a freertos notification
*/
class NotifiedWorkerThread : public OSThread
{
2020-10-09 09:10:44 +08:00
public:
NotifiedWorkerThread(const char *name) : OSThread(name) {}
2020-10-09 09:10:44 +08:00
/**
* Notify this thread so it can run
*/
void notify(uint32_t v, bool overwrite);
2020-10-09 09:10:44 +08:00
/**
* Notify from an ISR
*
* This must be inline or IRAM_ATTR on ESP32
*/
void notifyFromISR(BaseType_t *highPriWoken, uint32_t v, bool overwrite) { notify(v, overwrite); }
2020-10-09 09:10:44 +08:00
/**
* Schedule a notification to fire in delay msecs
2020-10-09 09:10:44 +08:00
*/
void notifyLater(uint32_t delay, uint32_t v, bool overwrite);
protected:
virtual void onNotify(uint32_t notification) = 0;
virtual uint32_t runOnce();
private:
2020-10-09 09:10:44 +08:00
/**
* The notification that was most recently used to wake the thread. Read from runOnce()
2020-10-09 09:10:44 +08:00
*/
uint32_t notification = 0;
2020-10-09 09:10:44 +08:00
};
} // namespace concurrency