/* * thread.cpp * * Created on: Sep 14, 2023 * Author: Dario */ #include #include #include #include #include namespace sta { namespace tacos { TacosThread::TacosThread(const char* name, osPriority_t prio) : RtosThread(RtosHandle(Handle::Deferred(&instance_))), instance_{ NULL }, attribs_{ .name = name, .priority = prio } {} TacosThread::TacosThread() : RtosThread(RtosHandle(Handle::Deferred(&instance_))), instance_{ NULL }, attribs_{ } {} void TacosThread::entry_point(void* arg) { STA_ASSERT(arg != nullptr); TacosThread* instance = reinterpret_cast(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; } TacosThread::~TacosThread(){} } // namespace tacos } // namespace sta