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:
@@ -52,7 +52,7 @@ mixer_open(Mixer *mixer)
|
||||
{
|
||||
assert(mixer != nullptr);
|
||||
|
||||
const std::lock_guard<Mutex> protect(mixer->mutex);
|
||||
const std::scoped_lock<Mutex> protect(mixer->mutex);
|
||||
|
||||
if (mixer->open)
|
||||
return;
|
||||
@@ -82,7 +82,7 @@ mixer_close(Mixer *mixer)
|
||||
{
|
||||
assert(mixer != nullptr);
|
||||
|
||||
const std::lock_guard<Mutex> protect(mixer->mutex);
|
||||
const std::scoped_lock<Mutex> protect(mixer->mutex);
|
||||
|
||||
if (mixer->open)
|
||||
mixer_close_internal(mixer);
|
||||
@@ -119,7 +119,7 @@ mixer_get_volume(Mixer *mixer)
|
||||
if (mixer->plugin.global && !mixer->failed)
|
||||
mixer_open(mixer);
|
||||
|
||||
const std::lock_guard<Mutex> protect(mixer->mutex);
|
||||
const std::scoped_lock<Mutex> protect(mixer->mutex);
|
||||
|
||||
if (mixer->open) {
|
||||
try {
|
||||
@@ -143,7 +143,7 @@ mixer_set_volume(Mixer *mixer, unsigned volume)
|
||||
if (mixer->plugin.global && !mixer->failed)
|
||||
mixer_open(mixer);
|
||||
|
||||
const std::lock_guard<Mutex> protect(mixer->mutex);
|
||||
const std::scoped_lock<Mutex> protect(mixer->mutex);
|
||||
|
||||
if (mixer->open)
|
||||
mixer->SetVolume(volume);
|
||||
|
Reference in New Issue
Block a user