From 58f6751891a06d4ff8f5328b60d80e9d1c2834ea Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 17 Feb 2021 00:29:39 -0800 Subject: [PATCH] UI: Avoid PathBrowser lock with no remote files. Only needs locks once the thread starts. --- Common/File/PathBrowser.cpp | 18 ++++++++++++------ Common/File/PathBrowser.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Common/File/PathBrowser.cpp b/Common/File/PathBrowser.cpp index 7bd70e2063..26dce5e338 100644 --- a/Common/File/PathBrowser.cpp +++ b/Common/File/PathBrowser.cpp @@ -146,22 +146,22 @@ void PathBrowser::SetPath(const std::string &path) { } void PathBrowser::HandlePath() { - std::lock_guard guard(pendingLock_); - if (!path_.empty() && path_[0] == '!') { + if (pendingActive_) + ResetPending(); ready_ = true; - pendingCancel_ = true; - pendingPath_.clear(); return; } if (!startsWith(path_, "http://") && !startsWith(path_, "https://")) { + if (pendingActive_) + ResetPending(); ready_ = true; - pendingCancel_ = true; - pendingPath_.clear(); return; } + std::lock_guard guard(pendingLock_); ready_ = false; + pendingActive_ = true; pendingCancel_ = false; pendingFiles_.clear(); pendingPath_ = path_; @@ -201,6 +201,12 @@ void PathBrowser::HandlePath() { }); } +void PathBrowser::ResetPending() { + std::lock_guard guard(pendingLock_); + pendingCancel_ = true; + pendingPath_.clear(); +} + bool PathBrowser::IsListingReady() { return ready_; } diff --git a/Common/File/PathBrowser.h b/Common/File/PathBrowser.h index 83e5e2f900..0873b2f58b 100644 --- a/Common/File/PathBrowser.h +++ b/Common/File/PathBrowser.h @@ -37,6 +37,7 @@ public: private: void HandlePath(); + void ResetPending(); std::string path_; std::string pendingPath_; @@ -44,6 +45,7 @@ private: std::condition_variable pendingCond_; std::mutex pendingLock_; std::thread pendingThread_; + bool pendingActive_ = false; bool pendingCancel_ = false; bool pendingStop_ = false; bool ready_ = false;