| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef MUTEX_H |
| 4 | #define MUTEX_H |
| 5 | |
| 6 | #include <QMutex> |
| 7 | #include <QObject> |
| 8 | |
| 9 | class RSSGUARD_DLLSPEC Mutex : public QObject { |
| 10 | Q_OBJECT |
| 11 | |
| 12 | public: |
| 13 | explicit Mutex(QObject* parent = nullptr); |
| 14 | virtual ~Mutex(); |
| 15 | |
| 16 | // Main methods. |
| 17 | bool tryLock(); |
| 18 | bool tryLock(int timeout); |
| 19 | |
| 20 | // Identifies if mutes is locked or not. |
| 21 | bool isLocked() const; |
| 22 | |
| 23 | operator QMutex*() const; |
| 24 | |
| 25 | public slots: |
| 26 | void lock(); |
| 27 | void unlock(); |
| 28 | |
| 29 | protected: |
| 30 | // These methods set proper value for m_isLocked and emit signals. |
| 31 | void setLocked(); |
| 32 | void setUnlocked(); |
| 33 | |
| 34 | signals: |
| 35 | void locked(); |
| 36 | void unlocked(); |
| 37 | |
| 38 | private: |
| 39 | QScopedPointer<QMutex> m_mutex; |
| 40 | bool m_isLocked; |
| 41 | }; |
| 42 | |
| 43 | #endif // MUTEX_H |