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
qrefcount.h
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
ifndef
QREFCOUNT_H
6
#
define
QREFCOUNT_H
7
8
#
include
<
QtCore
/
qatomic
.
h
>
9
10
QT_BEGIN_NAMESPACE
11
12
13
namespace
QtPrivate
14
{
15
16
class
RefCount
17
{
18
public
:
19
inline
bool
ref
()
noexcept
{
20
int
count = atomic.loadRelaxed();
21
if
(count != -1)
// !isStatic
22
atomic.ref();
23
return
true
;
24
}
25
26
inline
bool
deref
()
noexcept
{
27
int
count = atomic.loadRelaxed();
28
if
(count == -1)
// isStatic
29
return
true
;
30
return
atomic.deref();
31
}
32
33
bool
isStatic
()
const
noexcept
34
{
35
// Persistent object, never deleted
36
return
atomic.loadRelaxed() == -1;
37
}
38
39
bool
isShared
()
const
noexcept
40
{
41
int
count = atomic.loadRelaxed();
42
return
(count != 1) && (count != 0);
43
}
44
45
void
initializeOwned
()
noexcept
{ atomic.storeRelaxed(1); }
46
void
initializeUnsharable
()
noexcept
{ atomic.storeRelaxed(0); }
47
48
QBasicAtomicInt
atomic
;
49
};
50
51
}
52
53
#
define
Q_REFCOUNT_INITIALIZE_STATIC
{
Q_BASIC_ATOMIC_INITIALIZER
(
-
1
)
}
54
#
define
Q_REFCOUNT_INITIALIZE_OWNED
{
Q_BASIC_ATOMIC_INITIALIZER
(
1
)
}
55
56
QT_END_NAMESPACE
57
58
#
endif
QtPrivate::RefCount
\inmodule QtCore
Definition
qrefcount.h:17
QtPrivate::RefCount::isShared
bool isShared() const noexcept
Definition
qrefcount.h:39
QtPrivate::RefCount::ref
bool ref() noexcept
Definition
qrefcount.h:19
QtPrivate::RefCount::atomic
QBasicAtomicInt atomic
Definition
qrefcount.h:48
QtPrivate::RefCount::initializeUnsharable
void initializeUnsharable() noexcept
Definition
qrefcount.h:46
QtPrivate::RefCount::initializeOwned
void initializeOwned() noexcept
Definition
qrefcount.h:45
QtPrivate::RefCount::deref
bool deref() noexcept
Definition
qrefcount.h:26
QtPrivate::RefCount::isStatic
bool isStatic() const noexcept
Definition
qrefcount.h:33
QtPrivate
Definition
qalloc.h:28
qtbase
src
corelib
tools
qrefcount.h
Generated on
for Qt by
1.16.1