36 #ifdef TESTING_MEM_POOL 37 #define noexcept_testing 38 #define static_construction_error() throw std::logic_error("static_construction_error") 40 #define noexcept_testing noexcept 41 #define static_construction_error() std::terminate() 80 template<
size_t total_size,
size_t block_shift>
83 static_assert(total_size > 0,
"total size must be larger than 0");
84 static_assert(total_size % (1 << block_shift) == 0,
"total size must be a multiple of block size");
85 static_assert((
MAX_PAGE_SHIFT >= block_shift) &&(block_shift > 0),
"block shift must be larger than 0");
103 m_size(total_size >> block_shift)
109 if (__builtin_uaddl_overflow(m_addr, total_size, &end))
143 std::lock_guard<std::mutex> lock(m_mutex);
150 m_next = start + total;
151 gsl::at(m_allocated, start) = total;
153 return m_addr + (start << block_shift);
156 throw std::bad_alloc();
176 if (start >= m_allocated.size())
180 std::lock_guard<std::mutex> lock(m_mutex);
197 {
return (
addr >= m_addr &&
addr < m_addr + total_size); }
213 std::lock_guard<std::mutex> lock(m_mutex);
218 auto size = gsl::at(m_allocated, (
addr - m_addr) >> block_shift);
223 return size << block_shift;
237 std::lock_guard<std::mutex> lock(m_mutex);
240 __builtin_memset(m_allocated.data(), 0xFF,
sizeof(m_allocated));
272 auto blocks = gsl::at(m_allocated, index);
282 if (check >= (total_size >> block_shift))
292 if ((
size & ((1 << block_shift) - 1)) != 0)
304 mutable std::mutex m_mutex;
305 std::array < integer_pointer, (total_size >> block_shift) > m_allocated;
#define static_construction_error()
uintptr_t integer_pointer
void uint64_t uint64_t uint64_t *rdx noexcept
auto index(const T virt, const F from)
constexpr const auto addr
size_type size(integer_pointer addr) const noexcept
void free(integer_pointer addr) noexcept
integer_pointer alloc(size_type size)
auto end(reversed_container< T > container) -> decltype(container.container.rend())
constexpr const auto mem_pool_used_index
mem_pool(integer_pointer addr) noexcept _testing
mem_pool & operator=(const mem_pool &)=delete
bool contains(integer_pointer addr) const noexcept
constexpr const auto mem_pool_free_index