本文整理汇总了C++中Locker::restoreLockState方法的典型用法代码示例。如果您正苦于以下问题:C++ Locker::restoreLockState方法的具体用法?C++ Locker::restoreLockState怎么用?C++ Locker::restoreLockState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locker
的用法示例。
在下文中一共展示了Locker::restoreLockState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeSessionsRecords
/**
* Removes the specified set of session ids from the persistent sessions collection and returns the
* number of sessions actually removed.
*/
int removeSessionsRecords(OperationContext* opCtx,
SessionsCollection& sessionsCollection,
const LogicalSessionIdSet& sessionIdsToRemove) {
if (sessionIdsToRemove.empty()) {
return 0;
}
Locker* locker = opCtx->lockState();
Locker::LockSnapshot snapshot;
invariant(locker->saveLockStateAndUnlock(&snapshot));
const auto guard = MakeGuard([&] {
UninterruptibleLockGuard noInterrupt(opCtx->lockState());
locker->restoreLockState(opCtx, snapshot);
});
// Top-level locks are freed, release any potential low-level (storage engine-specific
// locks). If we are yielding, we are at a safe place to do so.
opCtx->recoveryUnit()->abandonSnapshot();
// Track the number of yields in CurOp.
CurOp::get(opCtx)->yielded();
auto removed =
uassertStatusOK(sessionsCollection.findRemovedSessions(opCtx, sessionIdsToRemove));
uassertStatusOK(sessionsCollection.removeTransactionRecords(opCtx, removed));
return removed.size();
}
示例2: yieldAllLocks
// static
void QueryYield::yieldAllLocks(OperationContext* txn,
RecordFetcher* fetcher,
const std::string& planExecNS) {
// Things have to happen here in a specific order:
// 1) Tell the RecordFetcher to do any setup which needs to happen inside locks
// 2) Release lock mgr locks
// 3) Go to sleep
// 4) Touch the record we're yielding on, if there is one (RecordFetcher::fetch)
// 5) Reacquire lock mgr locks
Locker* locker = txn->lockState();
Locker::LockSnapshot snapshot;
if (fetcher) {
fetcher->setup();
}
// Nothing was unlocked, just return, yielding is pointless.
if (!locker->saveLockStateAndUnlock(&snapshot)) {
return;
}
// Top-level locks are freed, release any potential low-level (storage engine-specific
// locks). If we are yielding, we are at a safe place to do so.
txn->recoveryUnit()->abandonSnapshot();
MONGO_FAIL_POINT_BLOCK(setYieldAllLocksWait, customWait) {
const BSONObj& data = customWait.getData();
BSONElement customWaitNS = data["namespace"];
if (!customWaitNS || planExecNS == customWaitNS.str()) {
sleepFor(stdx::chrono::milliseconds(data["waitForMillis"].numberInt()));
}
}
// Track the number of yields in CurOp.
CurOp::get(txn)->yielded();
if (fetcher) {
fetcher->fetch();
}
locker->restoreLockState(snapshot);
}