summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2017-02-18 18:27:37 -0800
committerGravatar Yuri Kunde Schlesner2017-02-26 17:22:02 -0800
commit21f4f49c7aebbd3c716a4065a6d5b2c94c022008 (patch)
tree82784e1361dcb0ce2df2db548cc392155b3463bd /src
parentQt: Add (empty) status bar (diff)
downloadyuzu-21f4f49c7aebbd3c716a4065a6d5b2c94c022008.tar.gz
yuzu-21f4f49c7aebbd3c716a4065a6d5b2c94c022008.tar.xz
yuzu-21f4f49c7aebbd3c716a4065a6d5b2c94c022008.zip
SynchronizedWrapper: Add Lock convenience method
Diffstat (limited to 'src')
-rw-r--r--src/common/synchronized_wrapper.h43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/common/synchronized_wrapper.h b/src/common/synchronized_wrapper.h
index 04b4f2e51..4a1984c46 100644
--- a/src/common/synchronized_wrapper.h
+++ b/src/common/synchronized_wrapper.h
@@ -9,25 +9,8 @@
9 9
10namespace Common { 10namespace Common {
11 11
12/**
13 * Wraps an object, only allowing access to it via a locking reference wrapper. Good to ensure no
14 * one forgets to lock a mutex before acessing an object. To access the wrapped object construct a
15 * SyncronizedRef on this wrapper. Inspired by Rust's Mutex type
16 * (http://doc.rust-lang.org/std/sync/struct.Mutex.html).
17 */
18template <typename T> 12template <typename T>
19class SynchronizedWrapper { 13class SynchronizedWrapper;
20public:
21 template <typename... Args>
22 SynchronizedWrapper(Args&&... args) : data(std::forward<Args>(args)...) {}
23
24private:
25 template <typename U>
26 friend class SynchronizedRef;
27
28 std::mutex mutex;
29 T data;
30};
31 14
32/** 15/**
33 * Synchronized reference, that keeps a SynchronizedWrapper's mutex locked during its lifetime. This 16 * Synchronized reference, that keeps a SynchronizedWrapper's mutex locked during its lifetime. This
@@ -75,4 +58,28 @@ private:
75 SynchronizedWrapper<T>* wrapper; 58 SynchronizedWrapper<T>* wrapper;
76}; 59};
77 60
61/**
62 * Wraps an object, only allowing access to it via a locking reference wrapper. Good to ensure no
63 * one forgets to lock a mutex before acessing an object. To access the wrapped object construct a
64 * SyncronizedRef on this wrapper. Inspired by Rust's Mutex type
65 * (http://doc.rust-lang.org/std/sync/struct.Mutex.html).
66 */
67template <typename T>
68class SynchronizedWrapper {
69public:
70 template <typename... Args>
71 SynchronizedWrapper(Args&&... args) : data(std::forward<Args>(args)...) {}
72
73 SynchronizedRef<T> Lock() {
74 return {*this};
75 }
76
77private:
78 template <typename U>
79 friend class SynchronizedRef;
80
81 std::mutex mutex;
82 T data;
83};
84
78} // namespace Common 85} // namespace Common