Replace std::lock_guard and std::lock with std::scoped_lock (#1758)

std::scoped_lock was introduced in C++17 and is strictly better than
std::lock_guard as it supports locking any number of mutexes safely.
It's also easier to use than std::lock for locking multiple mutexes at
once.
This commit is contained in:
Tyler Veness
2019-07-08 22:58:39 -07:00
committed by Peter Johnson
parent 24d31df55a
commit 62be0392b6
79 changed files with 472 additions and 476 deletions

View File

@@ -43,7 +43,7 @@ InstanceImpl* InstanceImpl::Get(int inst) {
}
// slow path
std::lock_guard lock(s_mutex);
std::scoped_lock lock(s_mutex);
// static fast-path block
if (static_cast<unsigned int>(inst) <
@@ -66,7 +66,7 @@ int InstanceImpl::GetDefaultIndex() {
if (inst >= 0) return inst;
// slow path
std::lock_guard lock(s_mutex);
std::scoped_lock lock(s_mutex);
// double-check
inst = s_default;
@@ -79,7 +79,7 @@ int InstanceImpl::GetDefaultIndex() {
}
int InstanceImpl::Alloc() {
std::lock_guard lock(s_mutex);
std::scoped_lock lock(s_mutex);
return AllocImpl();
}
@@ -96,7 +96,7 @@ int InstanceImpl::AllocImpl() {
}
void InstanceImpl::Destroy(int inst) {
std::lock_guard lock(s_mutex);
std::scoped_lock lock(s_mutex);
if (inst < 0 || static_cast<unsigned int>(inst) >= s_instances.size()) return;
if (static_cast<unsigned int>(inst) <