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
10QT_BEGIN_NAMESPACE
11
12
13namespace QtPrivate
14{
15
17{
18public:
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
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
56QT_END_NAMESPACE
57
58#endif
\inmodule QtCore
Definition qrefcount.h:17
bool isShared() const noexcept
Definition qrefcount.h:39
bool ref() noexcept
Definition qrefcount.h:19
QBasicAtomicInt atomic
Definition qrefcount.h:48
void initializeUnsharable() noexcept
Definition qrefcount.h:46
void initializeOwned() noexcept
Definition qrefcount.h:45
bool deref() noexcept
Definition qrefcount.h:26
bool isStatic() const noexcept
Definition qrefcount.h:33