diff options
author | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2017-02-19 03:27:37 +0100 |
---|---|---|
committer | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2017-02-27 02:22:02 +0100 |
commit | 21f4f49c7aebbd3c716a4065a6d5b2c94c022008 (patch) | |
tree | 82784e1361dcb0ce2df2db548cc392155b3463bd /src/common/synchronized_wrapper.h | |
parent | Qt: Add (empty) status bar (diff) | |
download | yuzu-21f4f49c7aebbd3c716a4065a6d5b2c94c022008.tar yuzu-21f4f49c7aebbd3c716a4065a6d5b2c94c022008.tar.gz yuzu-21f4f49c7aebbd3c716a4065a6d5b2c94c022008.tar.bz2 yuzu-21f4f49c7aebbd3c716a4065a6d5b2c94c022008.tar.lz yuzu-21f4f49c7aebbd3c716a4065a6d5b2c94c022008.tar.xz yuzu-21f4f49c7aebbd3c716a4065a6d5b2c94c022008.tar.zst yuzu-21f4f49c7aebbd3c716a4065a6d5b2c94c022008.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/synchronized_wrapper.h | 43 |
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 @@ namespace Common { -/** - * Wraps an object, only allowing access to it via a locking reference wrapper. Good to ensure no - * one forgets to lock a mutex before acessing an object. To access the wrapped object construct a - * SyncronizedRef on this wrapper. Inspired by Rust's Mutex type - * (http://doc.rust-lang.org/std/sync/struct.Mutex.html). - */ template <typename T> -class SynchronizedWrapper { -public: - template <typename... Args> - SynchronizedWrapper(Args&&... args) : data(std::forward<Args>(args)...) {} - -private: - template <typename U> - friend class SynchronizedRef; - - std::mutex mutex; - T data; -}; +class SynchronizedWrapper; /** * Synchronized reference, that keeps a SynchronizedWrapper's mutex locked during its lifetime. This @@ -75,4 +58,28 @@ private: SynchronizedWrapper<T>* wrapper; }; +/** + * Wraps an object, only allowing access to it via a locking reference wrapper. Good to ensure no + * one forgets to lock a mutex before acessing an object. To access the wrapped object construct a + * SyncronizedRef on this wrapper. Inspired by Rust's Mutex type + * (http://doc.rust-lang.org/std/sync/struct.Mutex.html). + */ +template <typename T> +class SynchronizedWrapper { +public: + template <typename... Args> + SynchronizedWrapper(Args&&... args) : data(std::forward<Args>(args)...) {} + + SynchronizedRef<T> Lock() { + return {*this}; + } + +private: + template <typename U> + friend class SynchronizedRef; + + std::mutex mutex; + T data; +}; + } // namespace Common |