56 lines
1.1 KiB
C++
56 lines
1.1 KiB
C++
/*
|
|
* threads_signal.hpp
|
|
*
|
|
* Created on: Jun 20, 2021
|
|
* Author: erki
|
|
*/
|
|
|
|
#ifndef THREADS_INC_THREADS_SIGNAL_HPP_
|
|
#define THREADS_INC_THREADS_SIGNAL_HPP_
|
|
|
|
#include <freertos_os2.h>
|
|
|
|
namespace Threads
|
|
{
|
|
|
|
class PrimitiveThread;
|
|
|
|
template<typename T>
|
|
struct Signallable
|
|
{
|
|
using value_type = T;
|
|
|
|
static_assert(std::is_trivially_copyable_v<value_type>, "T must be trivially copyable.");
|
|
static_assert(std::is_default_constructible_v<value_type>, "T must be default constructible.");
|
|
|
|
virtual void emit(const T& t) = 0;
|
|
virtual BaseType_t emitFromIsr(const T& t) = 0;
|
|
};
|
|
|
|
template<>
|
|
struct Signallable<void>
|
|
{
|
|
using value_type = void;
|
|
|
|
virtual void emit() = 0;
|
|
virtual BaseType_t emitFromIsr() = 0;
|
|
};
|
|
|
|
template<typename R>
|
|
struct Awaitable
|
|
{
|
|
using result_type = R;
|
|
|
|
#ifdef INCLUDE_xTaskGetCurrentTaskHandle
|
|
virtual result_type await() = 0;
|
|
virtual result_type await(const long timeout) = 0;
|
|
#endif
|
|
|
|
virtual result_type await(const PrimitiveThread& currentThread) = 0;
|
|
virtual result_type await(const PrimitiveThread& currentThread, const long timeout) = 0;
|
|
};
|
|
|
|
}// namespace Threads
|
|
|
|
#endif /* THREADS_INC_THREADS_SIGNAL_HPP_ */
|