summaryrefslogtreecommitdiff
path: root/src/mongo/transport/service_executor_fixed.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/transport/service_executor_fixed.h')
-rw-r--r--src/mongo/transport/service_executor_fixed.h16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/mongo/transport/service_executor_fixed.h b/src/mongo/transport/service_executor_fixed.h
index 4e6f3b4f9cc..a68994d9fb3 100644
--- a/src/mongo/transport/service_executor_fixed.h
+++ b/src/mongo/transport/service_executor_fixed.h
@@ -29,6 +29,7 @@
#pragma once
+#include <boost/optional.hpp>
#include <memory>
#include "mongo/base/status.h"
@@ -80,18 +81,12 @@ private:
// Maintains the execution state (e.g., recursion depth) for executor threads
class ExecutorThreadContext {
public:
- ExecutorThreadContext(std::weak_ptr<ServiceExecutorFixed> serviceExecutor)
- : _executor(std::move(serviceExecutor)) {
- _adjustRunningExecutorThreads(1);
- }
+ ExecutorThreadContext(std::weak_ptr<ServiceExecutorFixed> serviceExecutor);
+ ~ExecutorThreadContext();
ExecutorThreadContext(ExecutorThreadContext&&) = delete;
ExecutorThreadContext(const ExecutorThreadContext&) = delete;
- ~ExecutorThreadContext() {
- _adjustRunningExecutorThreads(-1);
- }
-
void run(ServiceExecutor::Task task) {
// Yield here to improve concurrency, especially when there are more executor threads
// than CPU cores.
@@ -106,10 +101,11 @@ private:
}
private:
- void _adjustRunningExecutorThreads(int adjustment) {
+ boost::optional<int> _adjustRunningExecutorThreads(int adjustment) {
if (auto executor = _executor.lock()) {
- executor->_numRunningExecutorThreads.fetchAndAdd(adjustment);
+ return executor->_numRunningExecutorThreads.addAndFetch(adjustment);
}
+ return boost::none;
}
int _recursionDepth = 0;