diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
| commit | 294bc6ecabf14c09c9bc8644704921dcf97cb44e (patch) | |
| tree | 279b1e0bab53901a1647ac63c1c724f0f789a663 /src/mongo/executor/thread_pool_task_executor.cpp | |
| parent | 70be7c27a251621187a1de533462ae2bb1e3bd39 (diff) | |
| parent | 1e917fd798aa25b7066d4b414b51184f13d5a092 (diff) | |
Update upstream source from tag 'upstream/6.0.10'debian/6.0.10-1
Update to upstream version '6.0.10'
with Debian dir 2d176fa254eee97b139f712fec5709641335a8c3
Diffstat (limited to 'src/mongo/executor/thread_pool_task_executor.cpp')
| -rw-r--r-- | src/mongo/executor/thread_pool_task_executor.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/mongo/executor/thread_pool_task_executor.cpp b/src/mongo/executor/thread_pool_task_executor.cpp index d642252c7f5..c61db6f38b4 100644 --- a/src/mongo/executor/thread_pool_task_executor.cpp +++ b/src/mongo/executor/thread_pool_task_executor.cpp @@ -88,8 +88,9 @@ public: } // All fields except for "canceled" are guarded by the owning task executor's _mutex. The - // "canceled" field may be observed without holding _mutex, but may only be set while holding - // _mutex. + // "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. CallbackFn callback; AtomicWord<unsigned> canceled{0U}; @@ -823,18 +824,18 @@ void ThreadPoolTaskExecutor::runCallbackExhaust(std::shared_ptr<CallbackState> c std::move(cbHandle), cbState->canceled.load() ? kCallbackCanceledErrorStatus : Status::OK()); - if (!cbState->isFinished.load()) { + if (auto lk = stdx::unique_lock(_mutex); !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); } } |
