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

Method doLock

Core/InterProcessLock.cpp:57–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57bool FileLock::doLock(LockType lockType, bool wait, bool *tryAgain) {
58 if (!isFileLockValid()) {
59 return false;
60 }
61 bool unLockFirstIfNeeded = false;
62
63 if (lockType == SharedLockType) {
64 // don't want shared-lock to break any existing locks
65 if (m_sharedLockCount > 0 || m_exclusiveLockCount > 0) {
66 m_sharedLockCount++;
67 return true;
68 }
69 } else {
70 // don't want exclusive-lock to break existing exclusive-locks
71 if (m_exclusiveLockCount > 0) {
72 m_exclusiveLockCount++;
73 return true;
74 }
75 // prevent deadlock
76 if (m_sharedLockCount > 0) {
77 unLockFirstIfNeeded = true;
78 }
79 }
80
81 auto ret = platformLock(lockType, wait, unLockFirstIfNeeded, tryAgain);
82 if (ret) {
83 if (lockType == SharedLockType) {
84 m_sharedLockCount++;
85 } else {
86 m_exclusiveLockCount++;
87 }
88 }
89 return ret;
90}
91
92#ifndef MMKV_WIN32
93

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected