Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qmutex_p.h
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// Copyright (C) 2016 Intel Corporation.
3
// Copyright (C) 2012 Olivier Goffart <ogoffart@woboq.com>
4
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
5
// Qt-Security score:significant reason:default
6
7
#
ifndef
QMUTEX_P_H
8
#
define
QMUTEX_P_H
9
10
//
11
// W A R N I N G
12
// -------------
13
//
14
// This file is not part of the Qt API. It exists for the convenience of
15
// qmutex.cpp and qmutex_unix.cpp. This header file may change from version to
16
// version without notice, or even be removed.
17
//
18
// We mean it.
19
//
20
21
#
include
<
QtCore
/
private
/
qglobal_p
.
h
>
22
#
include
<
QtCore
/
qnamespace
.
h
>
23
#
include
<
QtCore
/
qmutex
.
h
>
24
#
include
<
QtCore
/
qatomic
.
h
>
25
#
include
<
QtCore
/
qdeadlinetimer
.
h
>
26
27
#
include
"qplatformdefs.h"
// _POSIX_VERSION
28
29
#
if
defined
(
Q_OS_UNIX
)
30
#
include
<
semaphore
.
h
>
31
#
endif
32
33
struct
timespec;
34
35
QT_BEGIN_NAMESPACE
36
37
// ### Qt7 remove this comment block
38
// We manipulate the pointer to this class in inline, atomic code,
39
// so syncqt mustn't mark them as private, so ELFVERSION:ignore-next
40
class
QMutexPrivate
41
{
42
public
:
43
~QMutexPrivate();
44
QMutexPrivate();
45
46
bool
wait(QDeadlineTimer timeout = QDeadlineTimer::Forever);
47
void
wakeUp()
noexcept
;
48
49
// Control the lifetime of the privates
50
QAtomicInt refCount;
51
int
id;
52
53
bool
ref()
54
{
55
Q_ASSERT(refCount.loadRelaxed() >= 0);
56
int
c;
57
do
{
58
c = refCount.loadRelaxed();
59
if
(c == 0)
60
return
false
;
61
}
while
(!refCount.testAndSetRelaxed(c, c + 1));
62
Q_ASSERT(refCount.loadRelaxed() >= 0);
63
return
true
;
64
}
65
void
deref()
66
{
67
Q_ASSERT(refCount.loadRelaxed() >= 0);
68
if
(!refCount.deref())
69
release();
70
Q_ASSERT(refCount.loadRelaxed() >= 0);
71
}
72
void
release();
73
static
QMutexPrivate *allocate();
74
75
QAtomicInt waiters;
// Number of threads waiting on this mutex. (may be offset by -BigNumber)
76
QAtomicInt possiblyUnlocked;
/* Boolean indicating that a timed wait timed out.
77
When it is true, a reference is held.
78
It is there to avoid a race that happens if unlock happens right
79
when the mutex is unlocked.
80
*/
81
enum
{ BigNumber = 0x100000 };
//Must be bigger than the possible number of waiters (number of threads)
82
void
derefWaiters(
int
value)
noexcept
;
83
84
//platform specific stuff
85
#
if
defined
(
Q_OS_UNIX
)
86
sem_t semaphore;
87
#
endif
88
};
89
90
QT_END_NAMESPACE
91
92
#
endif
// QMUTEX_P_H
QRecursiveMutex
\inmodule QtCore
Definition
qmutex.h:342
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
dummyFutexValue
static QMutexPrivate * dummyFutexValue()
Definition
qmutex.cpp:23
QBasicMutex
QMutex QBasicMutex
Definition
qmutex.h:360
qtbase
src
corelib
thread
qmutex_p.h
Generated on
for Qt by
1.16.1