All checks were successful
continuous-integration/drone/push Build is passing
Split thread into two different entities. Add exclusive signal.
85 lines
2.4 KiB
C++
85 lines
2.4 KiB
C++
/*
|
|
* threads_basethread.hpp
|
|
*
|
|
* Created on: Jun 11, 2021
|
|
* Author: erki
|
|
*/
|
|
|
|
#ifndef SKULLC_THREADS_PRIMITIVETHREAD_HPP_
|
|
#define SKULLC_THREADS_PRIMITIVETHREAD_HPP_
|
|
|
|
#include <cmsis_os.h>
|
|
#include <freertos_os2.h>
|
|
|
|
#include <type_traits>
|
|
#include <tuple>
|
|
|
|
namespace Threads
|
|
{
|
|
|
|
class PrimitiveThread
|
|
{
|
|
public:
|
|
PrimitiveThread() = delete;
|
|
PrimitiveThread(const PrimitiveThread&) = default;
|
|
PrimitiveThread(PrimitiveThread&&) = default;
|
|
PrimitiveThread& operator=(const PrimitiveThread&) = default;
|
|
PrimitiveThread& operator=(PrimitiveThread&&) = default;
|
|
|
|
osThreadId_t thread_id;
|
|
osThreadAttr_t attributes;
|
|
|
|
#ifdef INCLUDE_xTaskGetCurrentTaskHandle
|
|
static PrimitiveThread getCurrentThread();
|
|
#endif
|
|
|
|
[[nodiscard]] constexpr TaskHandle_t taskHandle() const
|
|
{
|
|
return static_cast<TaskHandle_t>(thread_id);
|
|
}
|
|
|
|
[[nodiscard]] BaseType_t notify(const long value, const eNotifyAction action);
|
|
|
|
/**
|
|
*
|
|
* @returns Tuple. First member indicating the return value of the underlying notify
|
|
* function, the second member indicating whether a higher priority task was awoken.
|
|
*
|
|
*/
|
|
[[nodiscard]] std::pair<BaseType_t, BaseType_t> notifyFromIsr(const long value, const eNotifyAction action);
|
|
|
|
void yield();
|
|
void sleep(const unsigned long delay);
|
|
void sleepUntil(const unsigned long deadline);
|
|
|
|
[[nodiscard]] bool notifyWait(const TickType_t delay) const;
|
|
[[nodiscard]] std::pair<bool, unsigned long> notifyWait(const TickType_t delay, const unsigned long set_on_entry, const unsigned long set_on_exit) const;
|
|
|
|
protected:
|
|
explicit PrimitiveThread(osThreadFunc_t function, const osThreadAttr_t& attrs);
|
|
|
|
template<typename F>
|
|
PrimitiveThread(F runner, const char* name, const osPriority_t priority, const std::uint32_t stack_size)
|
|
: PrimitiveThread(runner, constructThreadAttrs_(name, priority, stack_size))
|
|
{
|
|
static_assert(std::is_convertible_v<F, osThreadFunc_t>, "Run function F is not convertible to osThreadFunc_t (void (void*)).");
|
|
}
|
|
|
|
private:
|
|
explicit PrimitiveThread(TaskHandle_t threadHandle);
|
|
osThreadAttr_t constructThreadAttrs_(const char* name, const osPriority_t priority, const std::uint32_t stack_size);
|
|
};
|
|
|
|
inline bool operator==(const PrimitiveThread& lhs, const PrimitiveThread& rhs)
|
|
{
|
|
if (!lhs.thread_id || !rhs.thread_id)
|
|
return false;
|
|
|
|
return lhs.thread_id == rhs.thread_id;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
#endif /* SKULLC_THREADS_PRIMITIVETHREAD_HPP_ */
|