diff --git a/3rdparty/MaaDeps b/3rdparty/MaaDeps index 1827904a3..584864db0 160000 --- a/3rdparty/MaaDeps +++ b/3rdparty/MaaDeps @@ -1 +1 @@ -Subproject commit 1827904a3fe90da20d6dfd1640934b53e3303164 +Subproject commit 584864db01bda0a144a8e0ec27b8e10a7261aa9b diff --git a/source/MaaFramework/Base/AsyncRunner.hpp b/source/MaaFramework/Base/AsyncRunner.hpp index e78ba57f8..daaeb1de8 100644 --- a/source/MaaFramework/Base/AsyncRunner.hpp +++ b/source/MaaFramework/Base/AsyncRunner.hpp @@ -40,8 +40,8 @@ class AsyncRunner : public NonCopyable ProcessFunc process_; std::list> queue_; - std::mutex mutex_; - std::condition_variable cond_; + std::mutex queue_mutex_; + std::condition_variable queue_cond_; std::atomic_bool running_ = false; mutable std::shared_mutex status_mutex_; @@ -82,12 +82,12 @@ inline void AsyncRunner::release() exit_ = true; { - std::unique_lock lock(mutex_); - cond_.notify_all(); + std::unique_lock queue_lock(queue_mutex_); + queue_cond_.notify_all(); } { - std::unique_lock lock(compl_mutex_); + std::unique_lock compl_lock(compl_mutex_); compl_cond_.notify_all(); } @@ -102,11 +102,12 @@ inline void AsyncRunner::working() // LogFunc; while (!exit_) { - std::unique_lock lock(mutex_); + std::unique_lock queue_lock(queue_mutex_); if (queue_.empty()) { running_ = false; - cond_.wait(lock); + compl_cond_.notify_all(); + queue_cond_.wait(queue_lock); continue; } @@ -114,7 +115,7 @@ inline void AsyncRunner::working() auto [id, item] = std::move(queue_.front()); queue_.pop_front(); - lock.unlock(); + queue_lock.unlock(); std::unique_lock status_lock(status_mutex_); status_map_[id] = MaaStatus_Running; @@ -139,7 +140,7 @@ inline typename AsyncRunner::Id AsyncRunner::post(Item item, bool bl Id id = MaaInvalidId; { - std::unique_lock lock(mutex_); + std::unique_lock queue_lock(queue_mutex_); id = ++cross_inst_id_; queue_.emplace_back(id, std::move(item)); @@ -149,7 +150,7 @@ inline typename AsyncRunner::Id AsyncRunner::post(Item item, bool bl } running_ = true; - cond_.notify_one(); + queue_cond_.notify_one(); } if (block) { @@ -165,12 +166,12 @@ inline void AsyncRunner::wait(Id id) const // LogFunc << VAR(id); while (!exit_) { - std::unique_lock lock(compl_mutex_); + std::unique_lock compl_lock(compl_mutex_); if (id <= compl_id_) { return; } - compl_cond_.wait(lock); + compl_cond_.wait(compl_lock); } } @@ -180,19 +181,19 @@ inline void AsyncRunner::wait_all() const LogFunc; while (!exit_) { - std::unique_lock lock(compl_mutex_); + std::unique_lock compl_lock(compl_mutex_); if (!running_) { return; } - compl_cond_.wait(lock); + compl_cond_.wait(compl_lock); } } template inline MaaStatus AsyncRunner::status(Id id) const { - std::shared_lock lock(status_mutex_); + std::shared_lock status_lock(status_mutex_); auto iter = status_map_.find(id); if (iter == status_map_.end()) { @@ -207,19 +208,19 @@ inline void AsyncRunner::clear() // LogFunc; { - std::unique_lock lock(mutex_); + std::unique_lock queue_lock(queue_mutex_); queue_ = {}; - cond_.notify_all(); + queue_cond_.notify_all(); } { - std::unique_lock lock(compl_mutex_); + std::unique_lock compl_lock(compl_mutex_); compl_id_ = cross_inst_id_; compl_cond_.notify_all(); } { - std::unique_lock lock(status_mutex_); + std::unique_lock status_lock(status_mutex_); status_map_.clear(); } }