blob: 163bd2966f6aeb4802653c218f184474172af8ca (
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
38
39
40
41
42
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "utils_global.h"
#include <QtGlobal>
namespace Utils {
class QTCREATOR_UTILS_EXPORT Guard
{
Q_DISABLE_COPY(Guard)
public:
Guard();
~Guard();
bool isLocked() const;
int lockCount() const { return m_lockCount; }
// Prefer using GuardLocker when possible. These two methods are provided only for cases
// when locking and unlocking are done in separate methods, so that GuardLocker can't be
// used.
void lock();
void unlock();
private:
int m_lockCount = 0;
friend class GuardLocker;
};
class QTCREATOR_UTILS_EXPORT GuardLocker
{
Q_DISABLE_COPY(GuardLocker)
public:
GuardLocker(Guard &guard);
~GuardLocker();
private:
Guard &m_guard;
};
} // namespace Utils
|