mirror of
https://github.com/vimpunk/mio.git
synced 2025-12-06 08:46:51 +08:00
Update basic_mmap destructor sync behavior
This commit is contained in:
parent
98d0d875b5
commit
865d7f35ce
@ -188,6 +188,7 @@ inline mmap_context memory_map(const file_handle_type file_handle, const int64_t
|
||||
template<access_mode AccessMode, typename ByteT>
|
||||
basic_mmap<AccessMode, ByteT>::~basic_mmap()
|
||||
{
|
||||
conditional_sync();
|
||||
unmap();
|
||||
}
|
||||
|
||||
@ -278,8 +279,8 @@ void basic_mmap<AccessMode, ByteT>::map(const String& path, const size_type offs
|
||||
}
|
||||
|
||||
template<access_mode AccessMode, typename ByteT>
|
||||
void basic_mmap<AccessMode, ByteT>::map(const handle_type handle, const size_type offset,
|
||||
const size_type length, std::error_code& error)
|
||||
void basic_mmap<AccessMode, ByteT>::map(const handle_type handle,
|
||||
const size_type offset, const size_type length, std::error_code& error)
|
||||
{
|
||||
error.clear();
|
||||
if(handle == invalid_handle)
|
||||
|
||||
@ -325,6 +325,17 @@ private:
|
||||
{
|
||||
return !data() ? nullptr : data() - offset();
|
||||
}
|
||||
|
||||
/**
|
||||
* The destructor syncs changes to disk if `AccessMode` is `write`, but not
|
||||
* if it's `read`, but since the destructor cannot be templated, we need to
|
||||
* do SFINAE in a dedicated function, where one syncs and the other is a noop.
|
||||
*/
|
||||
template<access_mode A = AccessMode,
|
||||
typename = typename std::enable_if<A == access_mode::write>::type>
|
||||
void conditional_sync() { sync(); }
|
||||
template<access_mode A = AccessMode>
|
||||
typename std::enable_if<A == access_mode::read, void>::type conditional_sync() {}
|
||||
};
|
||||
|
||||
template<access_mode AccessMode, typename ByteT>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user