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:
@@ -160,7 +160,7 @@ PlayerControl::LockSetPause(bool pause_flag) noexcept
|
||||
void
|
||||
PlayerControl::LockSetBorderPause(bool _border_pause) noexcept
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
border_pause = _border_pause;
|
||||
}
|
||||
|
||||
@@ -198,14 +198,14 @@ PlayerControl::SetError(PlayerError type, std::exception_ptr &&_error) noexcept
|
||||
void
|
||||
PlayerControl::LockClearError() noexcept
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
ClearError();
|
||||
}
|
||||
|
||||
void
|
||||
PlayerControl::LockSetTaggedSong(const DetachedSong &song) noexcept
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
tagged_song.reset();
|
||||
tagged_song = std::make_unique<DetachedSong>(song);
|
||||
}
|
||||
@@ -225,7 +225,7 @@ PlayerControl::ReadTaggedSong() noexcept
|
||||
std::unique_ptr<DetachedSong>
|
||||
PlayerControl::LockReadTaggedSong() noexcept
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
const std::scoped_lock<Mutex> protect(mutex);
|
||||
return ReadTaggedSong();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user