summaryrefslogtreecommitdiffhomepage
path: root/opentrack-compat/qcopyable-mutex.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-25 07:27:03 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-25 07:49:19 +0200
commit24538cf3a3a91481851618791b11be81437563e4 (patch)
tree4bcc9b97721170829038fe778633382c3e8754bc /opentrack-compat/qcopyable-mutex.hpp
parent0f445ac2661b5454d491936bb780196b13d1f4ea (diff)
move portability classes to compat library
Diffstat (limited to 'opentrack-compat/qcopyable-mutex.hpp')
-rw-r--r--opentrack-compat/qcopyable-mutex.hpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/opentrack-compat/qcopyable-mutex.hpp b/opentrack-compat/qcopyable-mutex.hpp
new file mode 100644
index 00000000..f7f36f93
--- /dev/null
+++ b/opentrack-compat/qcopyable-mutex.hpp
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <QMutex>
+
+class MyMutex {
+private:
+ QMutex inner;
+
+public:
+ QMutex* operator->() { return &inner; }
+ QMutex* operator->() const { return &const_cast<MyMutex*>(this)->inner; }
+
+ MyMutex operator=(const MyMutex& datum)
+ {
+ auto mode =
+ datum->isRecursive()
+ ? QMutex::Recursive
+ : QMutex::NonRecursive;
+
+ return MyMutex(mode);
+ }
+
+ MyMutex(const MyMutex& datum)
+ {
+ *this = datum;
+ }
+
+ MyMutex(QMutex::RecursionMode mode = QMutex::NonRecursive) :
+ inner(mode)
+ {
+ }
+
+ QMutex* operator&()
+ {
+ return &inner;
+ }
+};