MCPcopy Create free account
hub / github.com/Tencent/MMKV / mmapOrCleanup

Method mmapOrCleanup

Core/MemoryFile.cpp:239–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237}
238
239bool 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
260void MemoryFile::reloadFromFile(size_t expectedCapacity) {
261# ifdef MMKV_ANDROID

Callers

nothing calls this directly

Calls 1

destroyAndUnLockMethod · 0.80

Tested by

no test coverage detected