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

Method reloadFromFile

Core/MemoryFile_Win32.cpp:224–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222}
223
224void MemoryFile::reloadFromFile(size_t expectedCapacity) {
225 if (isFileValid()) {
226 MMKVWarning("calling reloadFromFile while the cache [%s] is still valid", m_diskFile.getUTF8Path().c_str());
227 assert(0);
228 clearMemoryCache();
229 }
230 if (openIfNeeded()) {
231 FileLock fileLock(m_diskFile.getFd());
232 InterProcessLock lock(&fileLock, SharedLockType);
233 SCOPED_LOCK(&lock);
234
235 mmkv::getFileSize(m_diskFile.getFd(), m_size);
236 size_t expectedSize = std::max<size_t>(DEFAULT_MMAP_SIZE, roundUp<size_t>(expectedCapacity, DEFAULT_MMAP_SIZE));
237 // round up to (n * pagesize)
238 if (!m_readOnly && (m_size < expectedSize || (m_size % DEFAULT_MMAP_SIZE != 0))) {
239 InterProcessLock exclusiveLock(&fileLock, ExclusiveLockType);
240 SCOPED_LOCK(&exclusiveLock);
241
242 size_t roundSize = ((m_size / DEFAULT_MMAP_SIZE) + 1) * DEFAULT_MMAP_SIZE;;
243 roundSize = std::max<size_t>(expectedSize, roundSize);
244 truncate(roundSize, &fileLock);
245 } else {
246 mmapOrCleanup(&fileLock);
247 }
248 }
249}
250
251void MemoryFile::doCleanMemoryCache(bool forceClean) {
252 if (m_ptr) {

Callers

nothing calls this directly

Calls 4

getFileSizeFunction · 0.70
isFileValidFunction · 0.50
clearMemoryCacheFunction · 0.50
getFdMethod · 0.45

Tested by

no test coverage detected