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
4
#
ifndef
QREFCOUNT_H
5
#
define
QREFCOUNT_H
6
7
#
include
<
QtCore
/
qatomic
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
12
namespace
QtPrivate
13
{
14
15
class
RefCount
16
{
17
public
:
18
inline
bool
ref
()
noexcept
{
19
int
count = atomic.loadRelaxed();
20
if
(count != -1)
// !isStatic
21
atomic.ref();
22
return
true
;
23
}
24
25
inline
bool
deref
()
noexcept
{
26
int
count = atomic.loadRelaxed();
27
if
(count == -1)
// isStatic
28
return
true
;
29
return
atomic.deref();
30
}
31
32
bool
isStatic
()
const
noexcept
33
{
34
// Persistent object, never deleted
35
return
atomic.loadRelaxed() == -1;
36
}
37
38
bool
isShared
()
const
noexcept
39
{
40
int
count = atomic.loadRelaxed();
41
return
(count != 1) && (count != 0);
42
}
43
44
void
initializeOwned
()
noexcept
{ atomic.storeRelaxed(1); }
45
void
initializeUnsharable
()
noexcept
{ atomic.storeRelaxed(0); }
46
47
QBasicAtomicInt
atomic
;
48
};
49
50
}
51
52
#
define
Q_REFCOUNT_INITIALIZE_STATIC
{
Q_BASIC_ATOMIC_INITIALIZER
(
-
1
)
}
53
54
QT_END_NAMESPACE
55
56
#
endif
QtPrivate::RefCount
\inmodule QtCore
Definition
qrefcount.h:16
QtPrivate::RefCount::isShared
bool isShared() const noexcept
Definition
qrefcount.h:38
QtPrivate::RefCount::ref
bool ref() noexcept
Definition
qrefcount.h:18
QtPrivate::RefCount::atomic
QBasicAtomicInt atomic
Definition
qrefcount.h:47
QtPrivate::RefCount::initializeUnsharable
void initializeUnsharable() noexcept
Definition
qrefcount.h:45
QtPrivate::RefCount::initializeOwned
void initializeOwned() noexcept
Definition
qrefcount.h:44
QtPrivate::RefCount::deref
bool deref() noexcept
Definition
qrefcount.h:25
QtPrivate::RefCount::isStatic
bool isStatic() const noexcept
Definition
qrefcount.h:32
QtPrivate
Definition
qcompare.h:25
qtbase
src
corelib
tools
qrefcount.h
Generated on Sun Mar 9 2025 01:10:27 for Qt by
1.13.2