Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
10
11
12namespace QtPrivate
13{
14
16{
17public:
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); }
46
48};
49
50}
51
52#define Q_REFCOUNT_INITIALIZE_STATIC { Q_BASIC_ATOMIC_INITIALIZER(-1) }
53
55
56#endif
bool ref() noexcept
bool deref() noexcept
void storeRelaxed(T newValue) noexcept
T loadRelaxed() const noexcept
\inmodule QtCore
Definition qrefcount.h:16
bool isShared() const noexcept
Definition qrefcount.h:38
bool ref() noexcept
Definition qrefcount.h:18
QBasicAtomicInt atomic
Definition qrefcount.h:47
void initializeUnsharable() noexcept
Definition qrefcount.h:45
void initializeOwned() noexcept
Definition qrefcount.h:44
bool deref() noexcept
Definition qrefcount.h:25
bool isStatic() const noexcept
Definition qrefcount.h:32
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
GLenum GLenum GLsizei count