void LockerImpl::restoreWriteUnitOfWork(OperationContext* opCtx, const LockSnapshot& stateToRestore) { if (stateToRestore.globalMode != MODE_NONE) { restoreLockState(opCtx, stateToRestore); } invariant(_numResourcesToUnlockAtEndUnitOfWork == 0); for (auto it = _requests.begin(); it; it.next()) { invariant(_shouldDelayUnlock(it.key(), (it->mode))); invariant(it->unlockPending == 0); it->unlockPending++; } _numResourcesToUnlockAtEndUnitOfWork = static_cast<unsigned>(_requests.size()); beginWriteUnitOfWork(); }
bool LockerImpl<IsForMMAPV1>::unlock(ResourceId resId) { LockRequestsMap::Iterator it = _requests.find(resId); if (inAWriteUnitOfWork() && _shouldDelayUnlock(it.key(), (it->mode))) { if (!it->unlockPending) { _numResourcesToUnlockAtEndUnitOfWork++; } it->unlockPending++; // unlockPending will only be incremented if a lock is converted and unlock() is called // multiple times on one ResourceId. invariant(it->unlockPending < LockModesCount); return false; } // Don't attempt to unlock twice. This can happen when an interrupted global lock is destructed. if (it.finished()) return false; return _unlockImpl(&it); }