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:
@@ -87,7 +87,7 @@ QobuzClient::StartLogin()
|
||||
void
|
||||
QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
assert(!h.is_linked());
|
||||
|
||||
const bool was_empty = handlers.empty();
|
||||
@@ -114,7 +114,7 @@ QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept
|
||||
QobuzSession
|
||||
QobuzClient::GetSession() const
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
|
||||
if (error)
|
||||
std::rethrow_exception(error);
|
||||
@@ -129,7 +129,7 @@ void
|
||||
QobuzClient::OnQobuzLoginSuccess(QobuzSession &&_session) noexcept
|
||||
{
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
session = std::move(_session);
|
||||
login_request.reset();
|
||||
}
|
||||
@@ -141,7 +141,7 @@ void
|
||||
QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept
|
||||
{
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
error = std::move(_error);
|
||||
login_request.reset();
|
||||
}
|
||||
@@ -152,7 +152,7 @@ QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept
|
||||
void
|
||||
QobuzClient::InvokeHandlers() noexcept
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
while (!handlers.empty()) {
|
||||
auto &h = handlers.front();
|
||||
handlers.pop_front();
|
||||
|
||||
Reference in New Issue
Block a user