7 #ifndef ZPP_INCLUDE_ZPP_HEAP_HPP
8 #define ZPP_INCLUDE_ZPP_HEAP_HPP
10 #include <zephyr/kernel.h>
11 #include <zephyr/sys/__assert.h>
22 template <
class T_Heap>
58 return k_heap_aligned_alloc(
native_handle(), align, bytes, K_FOREVER);
85 return k_heap_aligned_alloc(
native_handle(), align, bytes, K_NO_WAIT);
96 template<
class T_Rep,
class T_Period>
98 try_allocate_for(
size_t bytes,
const std::chrono::duration<T_Rep, T_Period>& timeout) noexcept
112 template<
class T_Rep,
class T_Period>
114 try_allocate_for(
size_t bytes,
size_t align,
const std::chrono::duration<T_Rep, T_Period>& timeout) noexcept
158 template <
size_t T_Size>
169 k_heap_init(&m_heap, m_mem.data(), m_mem.size());
177 static constexpr
size_t size() noexcept {
202 std::array<uint8_t, T_Size> m_mem;
228 __ASSERT_NO_MSG(m_heap !=
nullptr);
239 template<
class T_Heap>
241 : m_heap(h.native_handle())
243 __ASSERT_NO_MSG(m_heap !=
nullptr);
259 __ASSERT_NO_MSG(m_heap !=
nullptr);
273 template<
class T_Heap>
276 m_heap = rhs.native_handle();
277 __ASSERT_NO_MSG(m_heap !=
nullptr);
Heap memory allocater CRTP base class.
native_type * native_pointer
struct k_heap native_type
void * allocate(size_t bytes) noexcept
Allocate memory from this heap wainting forever.
base_heap(const base_heap &)=delete
auto native_handle() noexcept -> native_pointer
get the native zephyr heap handle.
void * try_allocate(size_t bytes, size_t align) noexcept
Allocate memory from this heap without waiting.
void * allocate(size_t bytes, size_t align) noexcept
Allocate memory from this heap waiting forever.
void * try_allocate_for(size_t bytes, size_t align, const std::chrono::duration< T_Rep, T_Period > &timeout) noexcept
Allocate memory from this heap waiting with a timeout.
void * try_allocate(size_t bytes) noexcept
Allocate memory from this heap without waiting.
base_heap(base_heap &&)=delete
constexpr base_heap() noexcept
default protected constructor so only derived objects can be created
void deallocate(void *mem) noexcept
Deallocate memory previously allocated.
native_type const * native_const_pointer
void * try_allocate_for(size_t bytes, const std::chrono::duration< T_Rep, T_Period > &timeout) noexcept
Allocate memory from this heap waiting with a timeout.
base_heap & operator=(const base_heap &)=delete
base_heap & operator=(base_heap &&)=delete
auto native_handle() const noexcept -> native_const_pointer
get the native zephyr heap handle.
constexpr heap_ref & operator=(native_pointer h) noexcept
assign new native heap object
constexpr heap_ref & operator=(T_Heap &rhs) noexcept
assign new heap object
constexpr auto native_handle() noexcept -> native_pointer
get the native zephyr heap handle.
constexpr heap_ref(native_pointer h) noexcept
reference native heap object
constexpr auto native_handle() const noexcept -> native_const_pointer
get the native zephyr heap handle.
constexpr heap_ref(T_Heap &h) noexcept
reference heap object
static constexpr size_t size() noexcept
Return the total size of this heap.
heap & operator=(heap &&)=delete
heap & operator=(const heap &)=delete
constexpr auto native_handle() noexcept -> native_pointer
get the native zephyr heap handle.
heap() noexcept
The default constructor.
constexpr auto native_handle() const noexcept -> native_const_pointer
get the native zephyr heap handle.
heap(const heap &)=delete
constexpr k_timeout_t to_timeout(const std::chrono::duration< T_Rep, T_Period > &d) noexcept
convert a duration to tick