| 237 | } |
| 238 | |
| 239 | bool MemoryFile::mmapOrCleanup(FileLock *fileLock) { |
| 240 | auto oldPtr = m_ptr; |
| 241 | auto mode = m_readOnly ? PROT_READ : (PROT_READ | PROT_WRITE); |
| 242 | m_ptr = (char *) ::mmap(m_ptr, m_size, mode, MAP_SHARED, m_diskFile.m_fd, 0); |
| 243 | if (m_ptr == MAP_FAILED) { |
| 244 | MMKVError("fail to mmap [%s], mode 0x%x, %s", m_diskFile.m_path.c_str(), mode, strerror(errno)); |
| 245 | m_ptr = nullptr; |
| 246 | |
| 247 | doCleanMemoryCache(true); |
| 248 | return false; |
| 249 | } |
| 250 | MMKVInfo("mmap to address [%p], oldPtr [%p], [%s]", m_ptr, oldPtr, m_diskFile.m_path.c_str()); |
| 251 | |
| 252 | if (m_isMayflyFD && fileLock) { |
| 253 | fileLock->destroyAndUnLock(); |
| 254 | } |
| 255 | |
| 256 | cleanMayflyFD(); |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | void MemoryFile::reloadFromFile(size_t expectedCapacity) { |
| 261 | # ifdef MMKV_ANDROID |
nothing calls this directly
no test coverage detected