rtos2-utils/include/sta/rtos/mempool.tpp
2023-09-22 17:53:04 +02:00

41 lines
918 B
C++

#ifndef STA_RTOS_MEMPOOL_TPP
#define STA_RTOS_MEMPOOL_TPP
#ifndef STA_RTOS_MEMPOOL_HPP
# error "Internal header. Use <sta/rtos/mempool.hpp> instead."
#endif // !STA_RTOS_MEMPOOL_HPP
#include <sta/debug/assert.hpp>
namespace sta
{
template <typename T>
RtosMemPool<T>::RtosMemPool()
{
}
template <typename T>
RtosMemPool<T>::RtosMemPool(uint32_t block_count, uint32_t block_size)
{
osMemoryPoolAttr_t mp_attr = { .name = "MemoryPool" };
handle_ = osMemoryPoolNew(block_size, block_count, &mp_attr);
STA_ASSERT_MSG(handle_ != nullptr, "Failed to Create RtosMemPool");
}
template <typename T>
void * RtosMemPool<T>::alloc(uint32_t timeout /* = osWaitForever */)
{
return osMemoryPoolAlloc(handle_, timeout);
}
template <typename T>
osStatus_t RtosMemPool<T>::free(void * block)
{
return osMemoryPoolFree(handle_, block);
}
} // namespace sta
#endif // STA_RTOS_MEMPOOL_TPP