mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-12-16 14:28:04 +00:00
Added reworked manager / statemachine tasks, thread implementation and new directory layout
This commit is contained in:
86
Tacos/src/thread.cpp
Normal file
86
Tacos/src/thread.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* thread.cpp
|
||||
*
|
||||
* Created on: Sep 14, 2023
|
||||
* Author: Dario
|
||||
*/
|
||||
|
||||
|
||||
#include <sta/tacos/thread.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
namespace tacos
|
||||
{
|
||||
TacosThread::TacosThread(const char* name, osPriority_t prio)
|
||||
: RtosThread(RtosHandle<osThreadId_t>(Handle::Deferred(&instance_))),
|
||||
attribs_{ .name = name, .priority = prio }
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void entry_point(void* arg)
|
||||
{
|
||||
STA_ASSERT(arg != nullptr);
|
||||
|
||||
TacosThread* instance = reinterpret_cast<TacosThread*>(arg) ;
|
||||
instance->loop();
|
||||
}
|
||||
|
||||
void TacosThread::start()
|
||||
{
|
||||
STA_ASSERT(!isRunning());
|
||||
|
||||
instance_ = osThreadNew(entry_point, this, &attribs_);
|
||||
|
||||
STA_ASSERT(instance_ != NULL);
|
||||
}
|
||||
|
||||
bool TacosThread::isRunning()
|
||||
{
|
||||
return instance_ != NULL;
|
||||
}
|
||||
|
||||
osThreadId_t TacosThread::getInstance()
|
||||
{
|
||||
STA_ASSERT(isRunning());
|
||||
|
||||
return instance_;
|
||||
}
|
||||
|
||||
const char* TacosThread::getName() const
|
||||
{
|
||||
return attribs_.name;
|
||||
}
|
||||
|
||||
void TacosThread::loop()
|
||||
{
|
||||
init();
|
||||
|
||||
while ((osEventFlagsGet(instance_) & STA_RTOS_THREAD_FLAG_TERMINATE) == 0)
|
||||
{
|
||||
func();
|
||||
}
|
||||
|
||||
instance_ = NULL;
|
||||
|
||||
osThreadExit();
|
||||
}
|
||||
|
||||
bool TacosThread::operator==(const TacosThread& other) const
|
||||
{
|
||||
return std::strcmp(this->getName(), other.getName()) == 0;
|
||||
}
|
||||
|
||||
bool TacosThread::operator<(const TacosThread& other) const
|
||||
{
|
||||
return std::strcmp(this->getName(), other.getName()) < 0;
|
||||
}
|
||||
} // namespace tacos
|
||||
} // namespace sta
|
||||
|
||||
Reference in New Issue
Block a user