summaryrefslogtreecommitdiff
path: root/src/mongo/executor/thread_pool_task_executor.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/executor/thread_pool_task_executor.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/executor/thread_pool_task_executor.cpp')
-rw-r--r--src/mongo/executor/thread_pool_task_executor.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/mongo/executor/thread_pool_task_executor.cpp b/src/mongo/executor/thread_pool_task_executor.cpp
index c61db6f38b4..d642252c7f5 100644
--- a/src/mongo/executor/thread_pool_task_executor.cpp
+++ b/src/mongo/executor/thread_pool_task_executor.cpp
@@ -88,9 +88,8 @@ public:
}
// All fields except for "canceled" are guarded by the owning task executor's _mutex. The
- // "canceled" field may be observed without holding _mutex only if we are checking if the value
- // is true. This is because once "canceled" stores true, we never set it back to false. The
- // "canceled" field may only be set while holding _mutex.
+ // "canceled" field may be observed without holding _mutex, but may only be set while holding
+ // _mutex.
CallbackFn callback;
AtomicWord<unsigned> canceled{0U};
@@ -824,18 +823,18 @@ void ThreadPoolTaskExecutor::runCallbackExhaust(std::shared_ptr<CallbackState> c
std::move(cbHandle),
cbState->canceled.load() ? kCallbackCanceledErrorStatus : Status::OK());
- if (auto lk = stdx::unique_lock(_mutex); !cbState->isFinished.load()) {
+ if (!cbState->isFinished.load()) {
TaskExecutor::CallbackFn callback = [](const CallbackArgs&) {};
{
+ auto lk = stdx::lock_guard(_mutex);
std::swap(cbState->callback, callback);
- lk.unlock();
}
callback(std::move(args));
- lk.lock();
// Leave the empty callback function if the request has been marked canceled or finished
// while running the callback to avoid leaking resources.
if (!cbState->canceled.load() && !cbState->isFinished.load()) {
+ auto lk = stdx::lock_guard(_mutex);
std::swap(callback, cbState->callback);
}
}