summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2020-02-10 14:23:37 +0000
committerevergreen <evergreen@mongodb.com>2020-02-10 14:23:37 +0000
commit25ffb326e1ecd57db0e1c309d0bcf6b8fd2e072c (patch)
tree199815c2e7dce17ac2b71f5b8fdb85587ff20f11 /src/mongo/db/concurrency
parent1a8fea4b5a2fe7ec14d88d1ce4e7c8a1eaaa03cd (diff)
downloadmongo-25ffb326e1ecd57db0e1c309d0bcf6b8fd2e072c.tar.gz
SERVER-45007 ResourceLock::lock() always requires OperationContext
Diffstat (limited to 'src/mongo/db/concurrency')
-rw-r--r--src/mongo/db/concurrency/d_concurrency.cpp4
-rw-r--r--src/mongo/db/concurrency/d_concurrency.h15
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp4
3 files changed, 13 insertions, 10 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency.cpp b/src/mongo/db/concurrency/d_concurrency.cpp
index 59a09012695..4138e537298 100644
--- a/src/mongo/db/concurrency/d_concurrency.cpp
+++ b/src/mongo/db/concurrency/d_concurrency.cpp
@@ -313,10 +313,6 @@ Lock::ParallelBatchWriterMode::ParallelBatchWriterMode(Locker* lockState)
: _pbwm(lockState, resourceIdParallelBatchWriterMode, MODE_X),
_shouldNotConflictBlock(lockState) {}
-void Lock::ResourceLock::lock(LockMode mode) {
- lock(nullptr, mode);
-}
-
void Lock::ResourceLock::lock(OperationContext* opCtx, LockMode mode) {
invariant(_result == LOCK_INVALID);
_locker->lock(opCtx, _rid, mode);
diff --git a/src/mongo/db/concurrency/d_concurrency.h b/src/mongo/db/concurrency/d_concurrency.h
index 03511aa8fd5..ddf7da380de 100644
--- a/src/mongo/db/concurrency/d_concurrency.h
+++ b/src/mongo/db/concurrency/d_concurrency.h
@@ -82,7 +82,7 @@ public:
ResourceLock(Locker* locker, ResourceId rid, LockMode mode)
: _rid(rid), _locker(locker), _result(LOCK_INVALID) {
- lock(mode);
+ lock(nullptr, mode);
}
ResourceLock(ResourceLock&& otherLock)
@@ -98,8 +98,15 @@ public:
}
}
- void lock(LockMode mode); // Uninterruptible
- void lock(OperationContext* opCtx, LockMode mode); // Interruptible
+ /**
+ * Acquires lock on this specified resource in the specified mode.
+ *
+ * If 'opCtx' is provided, it will be used to interrupt a LOCK_WAITING state.
+ *
+ * This function may throw an exception if it is interrupted.
+ */
+ void lock(OperationContext* opCtx, LockMode mode);
+
void unlock();
bool isLocked() const {
@@ -165,7 +172,7 @@ public:
* stdx::condition_variable_any
*/
void lock() {
- lock(MODE_X);
+ lock(nullptr, MODE_X);
}
};
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index 46216f388de..66c542ed1c8 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -240,7 +240,7 @@ TEST_F(DConcurrencyTestFixture, ResourceMutex) {
state.finish(3);
// Step 4: Try to regain the shared lock // transfers control to t1
- lk.lock(MODE_IS);
+ lk.lock(nullptr, MODE_IS);
// Step 6: CHeck we actually got back the shared lock
ASSERT(lk.isLocked());
@@ -2323,7 +2323,7 @@ TEST_F(DConcurrencyTestFixture, PBWMRespectsMaxTimeMS) {
auto opCtx2 = clientOpCtxPairs[1].second.get();
Lock::ResourceLock pbwm1(opCtx1->lockState(), resourceIdParallelBatchWriterMode);
- pbwm1.lock(MODE_X);
+ pbwm1.lock(nullptr, MODE_X);
opCtx2->setDeadlineAfterNowBy(Seconds{1}, ErrorCodes::ExceededTimeLimit);