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:
Rosen Penev
2021-11-11 16:19:32 -08:00
parent a8c77a6fba
commit 4e0e4c00bf
64 changed files with 196 additions and 196 deletions

View File

@@ -238,7 +238,7 @@ CurlInputStream::OnHeaders(unsigned status,
StringFormat<40>("got HTTP status %u",
status).c_str());
const std::lock_guard<Mutex> protect(mutex);
const std::scoped_lock<Mutex> protect(mutex);
if (IsSeekPending()) {
/* don't update metadata while seeking */
@@ -301,7 +301,7 @@ CurlInputStream::OnData(ConstBuffer<void> data)
{
assert(data.size > 0);
const std::lock_guard<Mutex> protect(mutex);
const std::scoped_lock<Mutex> protect(mutex);
if (IsSeekPending())
SeekDone();
@@ -317,7 +317,7 @@ CurlInputStream::OnData(ConstBuffer<void> data)
void
CurlInputStream::OnEnd()
{
const std::lock_guard<Mutex> protect(mutex);
const std::scoped_lock<Mutex> protect(mutex);
InvokeOnAvailable();
AsyncInputStream::SetClosed();
@@ -326,7 +326,7 @@ CurlInputStream::OnEnd()
void
CurlInputStream::OnError(std::exception_ptr e) noexcept
{
const std::lock_guard<Mutex> protect(mutex);
const std::scoped_lock<Mutex> protect(mutex);
postponed_exception = std::move(e);
if (IsSeekPending())