summaryrefslogtreecommitdiff
path: root/src/common/thread.h
diff options
context:
space:
mode:
authorGravatar Lioncash2019-04-01 12:29:59 -0400
committerGravatar Lioncash2019-04-01 12:53:47 -0400
commit781ab8407b50d303197ab6fb888ed35ecbcce23a (patch)
treeeaf2aabd5471c13fe89ac5f7da247b3bf1248e83 /src/common/thread.h
parentMerge pull request #2304 from lioncash/memsize (diff)
downloadyuzu-781ab8407b50d303197ab6fb888ed35ecbcce23a.tar.gz
yuzu-781ab8407b50d303197ab6fb888ed35ecbcce23a.tar.xz
yuzu-781ab8407b50d303197ab6fb888ed35ecbcce23a.zip
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.
Diffstat (limited to '')
-rw-r--r--src/common/thread.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/common/thread.h b/src/common/thread.h
index c5fc3533d..0cfd98be6 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -15,7 +15,7 @@ namespace Common {
15class Event { 15class Event {
16public: 16public:
17 void Set() { 17 void Set() {
18 std::lock_guard<std::mutex> lk(mutex); 18 std::lock_guard lk{mutex};
19 if (!is_set) { 19 if (!is_set) {
20 is_set = true; 20 is_set = true;
21 condvar.notify_one(); 21 condvar.notify_one();
@@ -23,14 +23,14 @@ public:
23 } 23 }
24 24
25 void Wait() { 25 void Wait() {
26 std::unique_lock<std::mutex> lk(mutex); 26 std::unique_lock lk{mutex};
27 condvar.wait(lk, [&] { return is_set; }); 27 condvar.wait(lk, [&] { return is_set; });
28 is_set = false; 28 is_set = false;
29 } 29 }
30 30
31 template <class Clock, class Duration> 31 template <class Clock, class Duration>
32 bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { 32 bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) {
33 std::unique_lock<std::mutex> lk(mutex); 33 std::unique_lock lk{mutex};
34 if (!condvar.wait_until(lk, time, [this] { return is_set; })) 34 if (!condvar.wait_until(lk, time, [this] { return is_set; }))
35 return false; 35 return false;
36 is_set = false; 36 is_set = false;
@@ -38,7 +38,7 @@ public:
38 } 38 }
39 39
40 void Reset() { 40 void Reset() {
41 std::unique_lock<std::mutex> lk(mutex); 41 std::unique_lock lk{mutex};
42 // no other action required, since wait loops on the predicate and any lingering signal will 42 // no other action required, since wait loops on the predicate and any lingering signal will
43 // get cleared on the first iteration 43 // get cleared on the first iteration
44 is_set = false; 44 is_set = false;
@@ -56,7 +56,7 @@ public:
56 56
57 /// Blocks until all "count" threads have called Sync() 57 /// Blocks until all "count" threads have called Sync()
58 void Sync() { 58 void Sync() {
59 std::unique_lock<std::mutex> lk(mutex); 59 std::unique_lock lk{mutex};
60 const std::size_t current_generation = generation; 60 const std::size_t current_generation = generation;
61 61
62 if (++waiting == count) { 62 if (++waiting == count) {