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

Method unlock

Core/InterProcessLock.cpp:163–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161#endif // MMKV_WIN32
162
163bool FileLock::unlock(LockType lockType) {
164 if (!isFileLockValid()) {
165 return false;
166 }
167 bool unlockToSharedLock = false;
168
169 if (lockType == SharedLockType) {
170 if (m_sharedLockCount == 0) {
171 return false;
172 }
173 // don't want shared-lock to break any existing locks
174 if (m_sharedLockCount > 1 || m_exclusiveLockCount > 0) {
175 m_sharedLockCount--;
176 return true;
177 }
178 } else {
179 if (m_exclusiveLockCount == 0) {
180 return false;
181 }
182 if (m_exclusiveLockCount > 1) {
183 m_exclusiveLockCount--;
184 return true;
185 }
186 // restore shared-lock when all exclusive-locks are done
187 if (m_sharedLockCount > 0) {
188 unlockToSharedLock = true;
189 }
190 }
191
192 auto ret = platformUnLock(unlockToSharedLock);
193 if (ret) {
194 if (lockType == SharedLockType) {
195 m_sharedLockCount--;
196 } else {
197 m_exclusiveLockCount--;
198 }
199 }
200 return ret;
201}
202
203void FileLock::destroyAndUnLock() {
204 platformUnLock(false);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected