diff options
Diffstat (limited to 'src/memory/include')
| -rw-r--r-- | src/memory/include/himem.hpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/memory/include/himem.hpp b/src/memory/include/himem.hpp index f71e912f..517ebfdf 100644 --- a/src/memory/include/himem.hpp +++ b/src/memory/include/himem.hpp @@ -57,21 +57,26 @@ class MappableRegion { } auto Get() -> cpp::span<std::byte> { - if (bytes_ != nullptr) { + if (bytes_ == nullptr) { return {}; } return {bytes_, size}; } auto Map(const HimemAlloc<size>& alloc) -> cpp::span<std::byte> { - if (bytes_ != nullptr) { - ESP_ERROR_CHECK(esp_himem_unmap(range_handle, bytes_, size)); - } + assert(bytes_ == nullptr); ESP_ERROR_CHECK(esp_himem_map(alloc.handle, range_handle, 0, 0, size, 0, reinterpret_cast<void**>(&bytes_))); return Get(); } + auto Unmap() -> void { + if (bytes_ != nullptr) { + ESP_ERROR_CHECK(esp_himem_unmap(range_handle, bytes_, size)); + bytes_ = nullptr; + } + } + // Not copyable or movable. MappableRegion(const MappableRegion&) = delete; MappableRegion& operator=(const MappableRegion&) = delete; |
