summaryrefslogtreecommitdiff
path: root/src/mongo/db/service_context.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2019-03-05 10:47:33 -0500
committerJason Carey <jcarey@argv.me>2019-03-11 10:26:49 -0400
commit1659623793b9d337e4061fc294ec258c99b1171e (patch)
tree592a21f84eb6bbbf8ca025bd04b7ccee89dc6db1 /src/mongo/db/service_context.cpp
parentbe65d84da8e84ea99a1075339bd49a23a688d756 (diff)
downloadmongo-1659623793b9d337e4061fc294ec258c99b1171e.tar.gz
SERVER-39960 Simplify opCtx::markKilled
Operation context currently relies on an elaborate dance between the client lock, _waitMutex, _waitCV and _numKillers to allow markKilled to tap the condvar an opctx is waiting on. After the introduction of batons on all opctx's, this is no longer necessary (as batons have their own support for being woken, while waiting on a condvar). Removing the special killing code will simplify opctx, and remove a lot of extra book keeping.
Diffstat (limited to 'src/mongo/db/service_context.cpp')
-rw-r--r--src/mongo/db/service_context.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp
index ee26756a642..ac8937dbc6c 100644
--- a/src/mongo/db/service_context.cpp
+++ b/src/mongo/db/service_context.cpp
@@ -248,21 +248,20 @@ ServiceContext::UniqueOperationContext ServiceContext::makeOperationContext(Clie
opCtx->setRecoveryUnit(std::make_unique<RecoveryUnitNoop>(),
WriteUnitOfWork::RecoveryUnitState::kNotInUnitOfWork);
}
- {
- stdx::lock_guard<Client> lk(*client);
- client->setOperationContext(opCtx.get());
- }
+ // The baton must be attached before attaching to a client
if (_transportLayer) {
_transportLayer->makeBaton(opCtx.get());
} else {
makeBaton(opCtx.get());
}
+ {
+ stdx::lock_guard<Client> lk(*client);
+ client->setOperationContext(opCtx.get());
+ }
return UniqueOperationContext(opCtx.release());
};
void ServiceContext::OperationContextDeleter::operator()(OperationContext* opCtx) const {
- opCtx->getBaton()->detach();
-
auto client = opCtx->getClient();
if (client->session()) {
_numCurrentOps.subtractAndFetch(1);
@@ -272,6 +271,8 @@ void ServiceContext::OperationContextDeleter::operator()(OperationContext* opCtx
stdx::lock_guard<Client> lk(*client);
client->resetOperationContext();
}
+ opCtx->getBaton()->detach();
+
onDestroy(opCtx, service->_clientObservers);
delete opCtx;
}
@@ -413,13 +414,10 @@ void ServiceContext::ServiceContextDeleter::operator()(ServiceContext* service)
}
BatonHandle ServiceContext::makeBaton(OperationContext* opCtx) const {
- auto baton = std::make_shared<DefaultBaton>(opCtx);
+ invariant(!opCtx->getBaton());
- {
- stdx::lock_guard<Client> lk(*opCtx->getClient());
- invariant(!opCtx->getBaton());
- opCtx->setBaton(baton);
- }
+ auto baton = std::make_shared<DefaultBaton>(opCtx);
+ opCtx->setBaton(baton);
return baton;
}