Making fsl::Task even more elegant
This commit is contained in:
parent
0111f3d210
commit
5139921a22
1 changed files with 4 additions and 8 deletions
|
@ -17,20 +17,16 @@ namespace fsl {
|
||||||
template<typename T, uint32_t stackSize> class Task {
|
template<typename T, uint32_t stackSize> class Task {
|
||||||
public:
|
public:
|
||||||
Task(UBaseType_t priority, void (T::*fp)()) : m_priority(priority), m_fp(fp) {}
|
Task(UBaseType_t priority, void (T::*fp)()) : m_priority(priority), m_fp(fp) {}
|
||||||
void Start(SemaphoreHandle_t doneSem = nullptr, bool waitForInit = false) {
|
void Start() {
|
||||||
m_handle = xTaskCreateStatic(staticBridge, getName(), sizeof(m_stack)/sizeof(m_stack[0]),
|
m_handle = xTaskCreateStatic(taskStaticBridge, getName(), sizeof(m_stack)/sizeof(m_stack[0]),
|
||||||
this, m_priority, m_stack, &m_tcb);
|
this, m_priority, m_stack, &m_tcb);
|
||||||
}
|
}
|
||||||
virtual ~Task() {};
|
virtual ~Task() {};
|
||||||
virtual char const * getName() = 0;
|
virtual char const * getName() = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void staticBridge(void *taskObj) {
|
static void taskStaticBridge(void *_this) {
|
||||||
reinterpret_cast<Task<T, stackSize>*>(taskObj)->taskBridge();
|
(static_cast<T*>(reinterpret_cast<Task<T, stackSize>*>(_this))->*(reinterpret_cast<Task<T, stackSize>*>(_this)->m_fp))();
|
||||||
}
|
|
||||||
|
|
||||||
void taskBridge() {
|
|
||||||
(static_cast<T*>(this)->*m_fp)();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskHandle_t m_handle;
|
TaskHandle_t m_handle;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue