adding mayfly fd on iOS

This commit is contained in:
guoling
2025-01-24 20:15:02 +08:00
parent b1bc572955
commit 561d56ca75
7 changed files with 107 additions and 44 deletions
+26 -16
View File
@@ -26,20 +26,23 @@
#endif
namespace mmkv {
FileLock::~FileLock() {
if (m_exclusiveLockCount > 0) {
if (isFileLockValid()) {
if (m_exclusiveLockCount > 0) {
#ifdef MMKV_WIN32
// only win32 file lock requires double unlock
if (m_sharedLockCount > 0) {
platformUnLock(true);
}
// only win32 file lock requires double unlock
if (m_sharedLockCount > 0) {
platformUnLock(true);
}
#endif
m_sharedLockCount = 0;
m_exclusiveLockCount = 0;
platformUnLock(false);
} else if (m_sharedLockCount > 0) {
m_sharedLockCount = 0;
platformUnLock(false);
m_sharedLockCount = 0;
m_exclusiveLockCount = 0;
platformUnLock(false);
} else if (m_sharedLockCount > 0) {
m_sharedLockCount = 0;
platformUnLock(false);
}
}
}
@@ -148,13 +151,11 @@ bool FileLock::platformUnLock(bool unlockToSharedLock) {
}
# endif
int cmd = unlockToSharedLock ? LOCK_SH : LOCK_UN;
auto ret = flock(m_fd, cmd);
if (ret != 0) {
MMKVError("fail to unlock fd=%d, ret=%d, error:%s", m_fd, ret, strerror(errno));
if (flock(m_fd, cmd) != 0) {
MMKVError("fail to unlock fd=%d, error:%d(%s)", m_fd, errno, strerror(errno));
return false;
} else {
return true;
}
return true;
}
#endif // MMKV_WIN32
@@ -199,4 +200,13 @@ bool FileLock::unlock(LockType lockType) {
return ret;
}
void FileLock::destroyLock() {
// TODO: test Win32 file lock
m_fd = MMKVFileHandleInvalidValue;
// TODO: do we need to reset these as well?
// m_sharedLockCount = 0;
// m_exclusiveLockCount = 0;
}
} // namespace mmkv