diff options
author | B. Stack <bgstack15@gmail.com> | 2023-11-27 10:33:00 -0500 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2023-11-27 10:33:00 -0500 |
commit | 2e61b9b6258f29c03cb3b0da48282f3a87590702 (patch) | |
tree | 2be66dfaf965d246ea2df6248c7890208887e6bb /zen/thread.h | |
parent | add upstream 13.1 (diff) | |
download | FreeFileSync-2e61b9b6258f29c03cb3b0da48282f3a87590702.tar.gz FreeFileSync-2e61b9b6258f29c03cb3b0da48282f3a87590702.tar.bz2 FreeFileSync-2e61b9b6258f29c03cb3b0da48282f3a87590702.zip |
add upstream 13.213.2
Diffstat (limited to 'zen/thread.h')
-rw-r--r-- | zen/thread.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/zen/thread.h b/zen/thread.h index 27b4c9b8..27e23b4a 100644 --- a/zen/thread.h +++ b/zen/thread.h @@ -203,10 +203,13 @@ public: //non-blocking wait()-alternative: context of controlling thread: void notifyWhenDone(const std::function<void()>& onCompletion /*noexcept! runs on worker thread!*/) { - std::lock_guard dummy(workLoad_.ref().lock); + std::unique_lock dummy(workLoad_.ref().lock); if (workLoad_.ref().tasksPending == 0) + { + dummy.unlock(); onCompletion(); + } else workLoad_.ref().onCompletionCallbacks.push_back(onCompletion); } @@ -242,8 +245,7 @@ private: if (--(workLoad.tasksPending) == 0) if (!workLoad.onCompletionCallbacks.empty()) { - std::vector<std::function<void()>> callbacks; - callbacks.swap(workLoad.onCompletionCallbacks); + std::vector<std::function<void()>> callbacks = std::exchange(workLoad.onCompletionCallbacks, {}); dummy.unlock(); for (const auto& cb : callbacks) |