Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
QtSync.h
Go to the documentation of this file.
1#pragma once
2#include <QMutexLocker>
3#include <misc/global.h>
4
5namespace sf
6{
7
14{
15 protected:
19 QtSync() = default;
20
27 QtSync(const QtSync&) {}
28
35 {
36 return *this;
37 }
38
39 public:
44 {
45 public:
49 explicit Lock(QtSync* sync, bool tryLock = false, int timeout = -1)
50 : _mutex(sync->_mutex)
51 , _locked(false)
52 {
53 _locked = lock(tryLock, timeout);
54 }
55
60 {
61 unlock();
62 }
63
68 inline explicit operator bool() const
69 {
70 return _locked;
71 }
72
79 [[nodiscard]] bool lock(bool tryLock = false, int timeout = -1);
80
84 inline void unlock()
85 {
86 // Only when locked un lock is needed.
87 if (_locked)
88 {
89 _mutex.unlock();
90 _locked = false;
91 }
92 }
93
94 private:
98 QMutex& _mutex;
102 bool _locked;
103 };
104
105 private:
106 QMutex _mutex;
107};
108
109}// namespace sf
Class locking the mutex.
Definition QtSync.h:44
Lock(QtSync *sync, bool tryLock=false, int timeout=-1)
Locks the QMutex object in the QSync object.
Definition QtSync.h:49
~Lock()
Destructor unlocking when locked.
Definition QtSync.h:59
bool lock(bool tryLock=false, int timeout=-1)
Used when try locking the sync/mutex.
void unlock()
Unlocks the mutex.
Definition QtSync.h:84
QSync provides a interface to build classes that act like monitors.
Definition QtSync.h:14
QtSync & operator=(const QtSync &)
Does not copy the Mutex object, since the new object is not being used in any of its own member funct...
Definition QtSync.h:34
QtSync()=default
Only by inheritance is allowed to create this instance.
QtSync(const QtSync &)
Copy constructor does not copy the Mutex object, since the new object is not being used in any of its...
Definition QtSync.h:27
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10