Qt Utilities
6.0.1
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
misc
trylocker.h
Go to the documentation of this file.
1
#ifndef THREADING_UTILS_TRYLOCKER_H
2
#define THREADING_UTILS_TRYLOCKER_H
3
4
#include <QtGlobal>
5
6
QT_FORWARD_DECLARE_CLASS(QMutex)
7
8
namespace
QtUtilities
{
9
13
template
<
typename
Mutex = QMutex>
class
TryLocker
{
14
public
:
18
TryLocker
(Mutex &mutex)
19
: m_mutex(mutex.tryLock() ? &mutex : nullptr)
20
{
21
}
22
27
~TryLocker
()
28
{
29
if
(m_mutex) {
30
m_mutex->unlock();
31
}
32
}
33
37
bool
isLocked
()
const
38
{
39
return
m_mutex !=
nullptr
;
40
}
41
45
operator
bool()
const
46
{
47
return
m_mutex !=
nullptr
;
48
}
49
50
private
:
51
Mutex *m_mutex;
52
};
53
}
// namespace QtUtilities
54
55
#endif // THREADING_UTILS_TRYLOCKER_H
QtUtilities::TryLocker::isLocked
bool isLocked() const
Returns whether the mutex could be locked.
Definition:
trylocker.h:37
QtUtilities::TryLocker::TryLocker
TryLocker(Mutex &mutex)
Tries to lock the specified mutex.
Definition:
trylocker.h:18
QtUtilities::TryLocker
Like QMutexLocker, but it just tries to lock the mutex.
Definition:
trylocker.h:13
QtUtilities
!
Definition:
trylocker.h:8
QtUtilities::TryLocker::~TryLocker
~TryLocker()
Unlocks the mutex specified when constructing.
Definition:
trylocker.h:27
Generated on Wed Oct 2 2019 15:53:38 for Qt Utilities by
1.8.16