mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-08-06 19:17:34 +00:00
Add thread wrapper class
This commit is contained in:
46
src/thread.cpp
Normal file
46
src/thread.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <sta/rtos/thread.hpp>
|
||||
|
||||
|
||||
#define IS_THREAD_SYS_FLAGS(flags) ( ( flags & STA_RTOS_THREAD_FLAGS_VALID_SYS_BITS ) == flags )
|
||||
#define IS_THREAD_USER_FLAGS(flags) ( ( flags & STA_RTOS_THREAD_FLAGS_VALID_USER_BITS ) == flags )
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
RtosThread::RtosThread()
|
||||
: handle_(nullptr)
|
||||
{}
|
||||
|
||||
RtosThread::RtosThread(const Handle & handle)
|
||||
: handle_{handle}
|
||||
{}
|
||||
|
||||
|
||||
void RtosThread::notify(uint32_t flags)
|
||||
{
|
||||
STA_ASSERT(handle_.get() != nullptr);
|
||||
STA_ASSERT_MSG(IS_THREAD_USER_FLAGS(flags), "Only user flags allowed");
|
||||
|
||||
osThreadFlagsSet(handle_.get(), flags);
|
||||
}
|
||||
|
||||
void RtosThread::sysNotify(uint32_t flags)
|
||||
{
|
||||
STA_ASSERT(handle_.get() != nullptr);
|
||||
STA_ASSERT_MSG(IS_THREAD_SYS_FLAGS(flags), "Only system flags allowed");
|
||||
|
||||
osThreadFlagsSet(handle_.get(), flags);
|
||||
}
|
||||
|
||||
|
||||
void RtosThread::requestTermination()
|
||||
{
|
||||
sysNotify(STA_RTOS_THREAD_FLAG_TERMINATE);
|
||||
}
|
||||
|
||||
void RtosThread::terminate()
|
||||
{
|
||||
STA_ASSERT(handle_.get() != nullptr);
|
||||
osThreadTerminate(handle_.get());
|
||||
}
|
||||
} // namespace sta
|
Reference in New Issue
Block a user