mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-10 01:55:59 +00:00
81 lines
1.6 KiB
C++
81 lines
1.6 KiB
C++
#ifndef STA_RTOS_HANDLE_HPP
|
|
#define STA_RTOS_HANDLE_HPP
|
|
|
|
#include <type_traits>
|
|
|
|
/**
|
|
* @defgroup STA_RTOS_HANDLE Handle
|
|
* @ingroup STA_RTOS_API
|
|
* @brief Helper for managing access to RTOS handles.
|
|
*/
|
|
|
|
namespace sta
|
|
{
|
|
/**
|
|
* @brief Helper for managing access to RTOS handles.
|
|
*
|
|
* @tparam T CMSIS RTOS2 handle type
|
|
*
|
|
* @ingroup STA_RTOS_HANDLE
|
|
*/
|
|
template <typename T>
|
|
class RtosHandle
|
|
{
|
|
public:
|
|
using handle_type = T; /**< Handle type */
|
|
|
|
// TODO Support integer type with sizeof(T) == sizeof(void *)
|
|
static_assert(std::is_same<handle_type, void *>::value, "Only compatible with void * handle types");
|
|
|
|
/**
|
|
* @brief Helper type for deferred handle evaluation.
|
|
*/
|
|
struct Deferred
|
|
{
|
|
/// @brief Handle variable address type
|
|
handle_type * pointer;
|
|
|
|
/**
|
|
* @brief Construct from handle address.
|
|
*
|
|
* @param handlePointer Handle variable address
|
|
*/
|
|
Deferred(handle_type * handlePointer);
|
|
};
|
|
|
|
public:
|
|
/**
|
|
* @brief Construct handle from value.
|
|
*
|
|
* @param handle Handle value
|
|
*/
|
|
RtosHandle(handle_type handle);
|
|
/**
|
|
* @brief Construct handle with deferred evaluation.
|
|
*
|
|
* @param handle Handle variable address
|
|
*/
|
|
RtosHandle(Deferred handle);
|
|
|
|
/**
|
|
* @brief Access handle value.
|
|
*
|
|
* If the deferred ctor was used the handle value is
|
|
* evaluated on the first call to this method.
|
|
*
|
|
* @return Handle value
|
|
*/
|
|
handle_type get();
|
|
|
|
private:
|
|
handle_type handle_; /**< Handle value or variable address */
|
|
bool deferred_; /**< Is handle evaluation deferred */
|
|
};
|
|
} // namespace sta
|
|
|
|
|
|
#include <sta/rtos/handle.tpp>
|
|
|
|
|
|
#endif // STA_RTOS_HANDLE_HPP
|