return *this;
}
~OwningMemoryBlock() {
- Memory::releaseMappedMemory(M);
+ if (M.base())
+ Memory::releaseMappedMemory(M);
}
void *base() const { return M.base(); }
/// The size as it was allocated. This is always greater or equal to the
/// size that was originally requested.
size_t allocatedSize() const { return M.allocatedSize(); }
MemoryBlock getMemoryBlock() const { return M; }
+ std::error_code release() {
+ std::error_code EC;
+ if (M.base()) {
+ EC = Memory::releaseMappedMemory(M);
+ M = MemoryBlock();
+ }
+ return EC;
+ }
private:
MemoryBlock M;
};
}
auto MB = std::move(I->second);
Blocks.erase(I);
- auto MBToRelease = MB.getMemoryBlock();
- if (auto EC = sys::Memory::releaseMappedMemory(MBToRelease))
+ if (auto EC = MB.release())
Err = joinErrors(std::move(Err), errorCodeToError(EC));
}
return Err;