| 172 | } |
| 173 | |
| 174 | bool MemoryFile::msync(SyncFlag syncFlag) { |
| 175 | if (m_readOnly) { |
| 176 | // there's no point in msync() readonly memory |
| 177 | return true; |
| 178 | } |
| 179 | if (m_ptr) { |
| 180 | if (FlushViewOfFile(m_ptr, m_size)) { |
| 181 | if (syncFlag == MMKV_SYNC && openIfNeeded()) { |
| 182 | auto ret = FlushFileBuffers(m_diskFile.getFd()); |
| 183 | if (!ret) { |
| 184 | MMKVError("fail to FlushFileBuffers [%s]:%d", m_diskFile.getUTF8Path().c_str(), GetLastError()); |
| 185 | } |
| 186 | cleanMayflyFD(); |
| 187 | return ret; |
| 188 | } |
| 189 | return true; |
| 190 | } |
| 191 | MMKVError("fail to FlushViewOfFile [%s]:%d", m_diskFile.getUTF8Path().c_str(), GetLastError()); |
| 192 | return false; |
| 193 | } |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | bool MemoryFile::mmapOrCleanup(FileLock *fileLock) { |
| 198 | auto mode = m_readOnly ? PAGE_READONLY : PAGE_READWRITE; |