summaryrefslogtreecommitdiff
path: root/src/mongo/db/default_baton.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2019-04-18 17:06:35 -0400
committerJason Carey <jcarey@argv.me>2019-05-01 21:45:07 -0400
commitb92621e4f6dc631023f0be2cfe311da71cd0f63a (patch)
tree0eb79c1277a9237e3ca3fcf34a5c381c448f385d /src/mongo/db/default_baton.cpp
parente549f39cd70a51054a48aa8765558db6b03b1df3 (diff)
downloadmongo-b92621e4f6dc631023f0be2cfe311da71cd0f63a.tar.gz
SERVER-40721 Add SubBaton
Introduce a subbaton, which can be created from a baton and used in place of one. The key distinction being that a subbaton can be detached before its parent baton. When this occurs, the subbaton will fail all scheduled work inside it and refuse future work.
Diffstat (limited to 'src/mongo/db/default_baton.cpp')
-rw-r--r--src/mongo/db/default_baton.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/mongo/db/default_baton.cpp b/src/mongo/db/default_baton.cpp
index 1154d377ccb..8ae455226cf 100644
--- a/src/mongo/db/default_baton.cpp
+++ b/src/mongo/db/default_baton.cpp
@@ -38,6 +38,12 @@
namespace mongo {
+namespace {
+
+const auto kDetached = Status(ErrorCodes::ShutdownInProgress, "Baton detached");
+
+} // namespace
+
DefaultBaton::DefaultBaton(OperationContext* opCtx) : _opCtx(opCtx) {}
DefaultBaton::~DefaultBaton() {
@@ -68,16 +74,16 @@ void DefaultBaton::detachImpl() noexcept {
}
for (auto& job : scheduled) {
- job(nullptr);
+ job(kDetached);
}
}
-void DefaultBaton::schedule(unique_function<void(OperationContext*)> func) noexcept {
+void DefaultBaton::schedule(Task func) noexcept {
stdx::unique_lock<stdx::mutex> lk(_mutex);
if (!_opCtx) {
lk.unlock();
- func(nullptr);
+ func(kDetached);
return;
}
@@ -108,7 +114,7 @@ Waitable::TimeoutState DefaultBaton::run_until(ClockSource* clkSource,
lk.unlock();
for (auto& job : toRun) {
- job(_opCtx);
+ job(Status::OK());
}
lk.lock();
}