general: Use deducation guides for std::lock_guard and std::unique_lock
Since C++17, the introduction of deduction guides for locking facilities means that we no longer need to hardcode the mutex type into the locks themselves, making it easier to switch mutex types, should it ever be necessary in the future.
This commit is contained in:
parent
d9b7bc4474
commit
781ab8407b
23 changed files with 77 additions and 75 deletions
|
@ -15,7 +15,7 @@ namespace Common {
|
|||
class Event {
|
||||
public:
|
||||
void Set() {
|
||||
std::lock_guard<std::mutex> lk(mutex);
|
||||
std::lock_guard lk{mutex};
|
||||
if (!is_set) {
|
||||
is_set = true;
|
||||
condvar.notify_one();
|
||||
|
@ -23,14 +23,14 @@ public:
|
|||
}
|
||||
|
||||
void Wait() {
|
||||
std::unique_lock<std::mutex> lk(mutex);
|
||||
std::unique_lock lk{mutex};
|
||||
condvar.wait(lk, [&] { return is_set; });
|
||||
is_set = false;
|
||||
}
|
||||
|
||||
template <class Clock, class Duration>
|
||||
bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) {
|
||||
std::unique_lock<std::mutex> lk(mutex);
|
||||
std::unique_lock lk{mutex};
|
||||
if (!condvar.wait_until(lk, time, [this] { return is_set; }))
|
||||
return false;
|
||||
is_set = false;
|
||||
|
@ -38,7 +38,7 @@ public:
|
|||
}
|
||||
|
||||
void Reset() {
|
||||
std::unique_lock<std::mutex> lk(mutex);
|
||||
std::unique_lock lk{mutex};
|
||||
// no other action required, since wait loops on the predicate and any lingering signal will
|
||||
// get cleared on the first iteration
|
||||
is_set = false;
|
||||
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
/// Blocks until all "count" threads have called Sync()
|
||||
void Sync() {
|
||||
std::unique_lock<std::mutex> lk(mutex);
|
||||
std::unique_lock lk{mutex};
|
||||
const std::size_t current_generation = generation;
|
||||
|
||||
if (++waiting == count) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue