summaryrefslogtreecommitdiffhomepage
path: root/opentrack/qcopyable-mutex.hpp
blob: f7f36f93280e4b122dfb10998acad4aa1878061f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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;
    }
};