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:
@@ -36,7 +36,7 @@ UpdateRemoveService::RunDeferred() noexcept
|
||||
std::forward_list<std::string> copy;
|
||||
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
std::swap(uris, copy);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ UpdateRemoveService::Remove(std::string &&uri)
|
||||
bool was_empty;
|
||||
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
was_empty = uris.empty();
|
||||
uris.emplace_front(std::move(uri));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user