From c75a0f7c753047b135a71cb679c8bfbe7da40f76 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 25 Apr 2019 19:43:45 +0200 Subject: [PATCH] neighbor/smbclient: call Run() with locked mutex --- src/neighbor/plugins/SmbclientNeighborPlugin.cxx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/neighbor/plugins/SmbclientNeighborPlugin.cxx b/src/neighbor/plugins/SmbclientNeighborPlugin.cxx index b6ed3b720..be944b0ec 100644 --- a/src/neighbor/plugins/SmbclientNeighborPlugin.cxx +++ b/src/neighbor/plugins/SmbclientNeighborPlugin.cxx @@ -76,7 +76,11 @@ public: List GetList() const noexcept override; private: + /** + * Caller must lock the mutex. + */ void Run() noexcept; + void ThreadFunc() noexcept; }; @@ -189,9 +193,12 @@ FindBeforeServerByURI(NeighborExplorer::List::const_iterator prev, inline void SmbclientNeighborExplorer::Run() noexcept { - List found = DetectServers(), lost; + List found, lost; - mutex.lock(); + { + const ScopeUnlock unlock(mutex); + found = DetectServers(); + } const auto found_before_begin = found.before_begin(); const auto found_end = found.end(); @@ -216,7 +223,7 @@ SmbclientNeighborExplorer::Run() noexcept i != found_end; prev = i, i = std::next(prev)) list.push_front(*i); - mutex.unlock(); + const ScopeUnlock unlock(mutex); for (auto &i : lost) listener.LostNeighbor(i); @@ -233,11 +240,8 @@ SmbclientNeighborExplorer::ThreadFunc() noexcept mutex.lock(); while (!quit) { - mutex.unlock(); - Run(); - mutex.lock(); if (quit) break;