2020-05-01 19:11:04 +00:00
|
|
|
#include "WorkerThread.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
void Thread::start(const char *name, size_t stackSize, uint32_t priority)
|
|
|
|
{
|
|
|
|
auto r = xTaskCreate(callRun, name, stackSize, this, priority, &taskHandle);
|
|
|
|
assert(r == pdPASS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::callRun(void *_this)
|
|
|
|
{
|
|
|
|
((Thread *)_this)->doRun();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorkerThread::doRun()
|
|
|
|
{
|
|
|
|
while (!wantExit) {
|
|
|
|
block();
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify this thread so it can run
|
|
|
|
*/
|
|
|
|
void NotifiedWorkerThread::notify(uint32_t v, eNotifyAction action)
|
|
|
|
{
|
|
|
|
xTaskNotify(taskHandle, v, action);
|
|
|
|
}
|
|
|
|
|
2020-05-14 19:46:29 +00:00
|
|
|
|
2020-05-01 19:11:04 +00:00
|
|
|
|
|
|
|
void NotifiedWorkerThread::block()
|
|
|
|
{
|
2020-05-02 15:29:51 +00:00
|
|
|
xTaskNotifyWait(0, // don't clear notification on entry
|
|
|
|
clearOnRead, ¬ification, portMAX_DELAY); // Wait forever
|
2020-05-01 19:11:04 +00:00
|
|
|
}
|