| 195 | } |
| 196 | |
| 197 | bool MemoryFile::mmapOrCleanup(FileLock *fileLock) { |
| 198 | auto mode = m_readOnly ? PAGE_READONLY : PAGE_READWRITE; |
| 199 | m_fileMapping = CreateFileMapping(m_diskFile.getFd(), nullptr, mode, 0, 0, nullptr); |
| 200 | if (!m_fileMapping) { |
| 201 | MMKVError("fail to CreateFileMapping [%s], mode %x, %d", m_diskFile.getUTF8Path().c_str(), mode, |
| 202 | GetLastError()); |
| 203 | return false; |
| 204 | } else { |
| 205 | auto viewMode = m_readOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS; |
| 206 | m_ptr = (char*)MapViewOfFile(m_fileMapping, viewMode, 0, 0, 0); |
| 207 | if (!m_ptr) { |
| 208 | MMKVError("fail to mmap [%s], mode %x, %d", m_diskFile.getUTF8Path().c_str(), viewMode, GetLastError()); |
| 209 | |
| 210 | doCleanMemoryCache(true); |
| 211 | return false; |
| 212 | } |
| 213 | MMKVInfo("mmap to address [%p], [%s]", m_ptr, m_diskFile.getUTF8Path().c_str()); |
| 214 | |
| 215 | if (m_isMayflyFD && fileLock) { |
| 216 | fileLock->destroyAndUnLock(); |
| 217 | } |
| 218 | |
| 219 | cleanMayflyFD(); |
| 220 | return true; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | void MemoryFile::reloadFromFile(size_t expectedCapacity) { |
| 225 | if (isFileValid()) { |
nothing calls this directly
no test coverage detected