summaryrefslogtreecommitdiff
path: root/src/mongo/db/operation_context.cpp
diff options
context:
space:
mode:
authorAndy Schwerin <Andy Schwerin schwerin@mongodb.com>2017-03-09 17:33:16 -0500
committerAndy Schwerin <Andy Schwerin schwerin@mongodb.com>2017-03-09 17:34:38 -0500
commit9352a9eb96a350b9fedeb2ff2984ef40fe80c894 (patch)
treeea5cb7e6890956e043fbc8212f528495fbe19f85 /src/mongo/db/operation_context.cpp
parent851e45451775131b255aa5c754b1fc4281861b1e (diff)
downloadmongo-9352a9eb96a350b9fedeb2ff2984ef40fe80c894.tar.gz
SERVER-25062 Implement interruptible sleep and waitFor methods on OperationContext.
Diffstat (limited to 'src/mongo/db/operation_context.cpp')
-rw-r--r--src/mongo/db/operation_context.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mongo/db/operation_context.cpp b/src/mongo/db/operation_context.cpp
index 8151fe97dfa..d0cb8e244ad 100644
--- a/src/mongo/db/operation_context.cpp
+++ b/src/mongo/db/operation_context.cpp
@@ -210,6 +210,22 @@ Status OperationContext::checkForInterruptNoAssert() {
return Status::OK();
}
+void OperationContext::sleepUntil(Date_t deadline) {
+ stdx::mutex m;
+ stdx::condition_variable cv;
+ stdx::unique_lock<stdx::mutex> lk(m);
+ invariant(stdx::cv_status::timeout ==
+ waitForConditionOrInterruptUntil(cv, lk, deadline, [] { return false; }));
+}
+
+void OperationContext::sleepFor(Milliseconds duration) {
+ stdx::mutex m;
+ stdx::condition_variable cv;
+ stdx::unique_lock<stdx::mutex> lk(m);
+ invariant(stdx::cv_status::timeout ==
+ waitForConditionOrInterruptFor(cv, lk, duration, [] { return false; }));
+}
+
void OperationContext::waitForConditionOrInterrupt(stdx::condition_variable& cv,
stdx::unique_lock<stdx::mutex>& m) {
uassertStatusOK(waitForConditionOrInterruptNoAssert(cv, m));
@@ -408,4 +424,8 @@ void OperationContext::setLockState(std::unique_ptr<Locker> locker) {
_locker = std::move(locker);
}
+Date_t OperationContext::getExpirationDateForWaitForValue(Milliseconds waitFor) {
+ return getServiceContext()->getPreciseClockSource()->now() + waitFor;
+}
+
} // namespace mongo