treewide: replace lock_guard with scoped_lock
SonarLint reports the latter to be better: std::scoped_lock basically provides the same feature as std::lock_guard, but is more generic: It can lock several mutexes at the same time, with a deadlock prevention mechanism (see {rule:cpp:S5524}). The equivalent code to perform simultaneous locking with std::lock_guard is significantly more complex. Therefore, it is simpler to use std::scoped_lock all the time, even when locking only one mutex (there will be no performance impact). Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
@@ -99,7 +99,7 @@ void
|
||||
SmbclientNeighborExplorer::Close() noexcept
|
||||
{
|
||||
{
|
||||
const std::lock_guard<Mutex> lock(mutex);
|
||||
const std::scoped_lock<Mutex> lock(mutex);
|
||||
quit = true;
|
||||
cond.notify_one();
|
||||
}
|
||||
@@ -110,7 +110,7 @@ SmbclientNeighborExplorer::Close() noexcept
|
||||
NeighborExplorer::List
|
||||
SmbclientNeighborExplorer::GetList() const noexcept
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@@ -175,7 +175,7 @@ UdisksNeighborExplorer::Close() noexcept
|
||||
NeighborExplorer::List
|
||||
UdisksNeighborExplorer::GetList() const noexcept
|
||||
{
|
||||
const std::lock_guard<Mutex> lock(mutex);
|
||||
const std::scoped_lock<Mutex> lock(mutex);
|
||||
|
||||
NeighborExplorer::List result;
|
||||
|
||||
@@ -192,7 +192,7 @@ UdisksNeighborExplorer::Insert(UDisks2::Object &&o) noexcept
|
||||
const NeighborInfo info = ToNeighborInfo(o);
|
||||
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
auto i = by_uri.emplace(o.GetUri(), info);
|
||||
if (!i.second)
|
||||
i.first->second = info;
|
||||
|
Reference in New Issue
Block a user