File indexing completed on 2026-09-28 09:24:40
0001
0002
0003
0004
0005 #ifndef QREFCOUNT_H
0006 #define QREFCOUNT_H
0007
0008 #include <QtCore/qatomic.h>
0009
0010 QT_BEGIN_NAMESPACE
0011
0012
0013 namespace QtPrivate
0014 {
0015
0016 class RefCount
0017 {
0018 public:
0019 inline bool ref() noexcept {
0020 int count = atomic.loadRelaxed();
0021 if (count != -1)
0022 atomic.ref();
0023 return true;
0024 }
0025
0026 inline bool deref() noexcept {
0027 int count = atomic.loadRelaxed();
0028 if (count == -1)
0029 return true;
0030 return atomic.deref();
0031 }
0032
0033 bool isStatic() const noexcept
0034 {
0035
0036 return atomic.loadRelaxed() == -1;
0037 }
0038
0039 bool isShared() const noexcept
0040 {
0041 int count = atomic.loadRelaxed();
0042 return (count != 1) && (count != 0);
0043 }
0044
0045 void initializeOwned() noexcept { atomic.storeRelaxed(1); }
0046 void initializeUnsharable() noexcept { atomic.storeRelaxed(0); }
0047
0048 QBasicAtomicInt atomic;
0049 };
0050
0051 }
0052
0053 #define Q_REFCOUNT_INITIALIZE_STATIC { Q_BASIC_ATOMIC_INITIALIZER(-1) }
0054 #define Q_REFCOUNT_INITIALIZE_OWNED { Q_BASIC_ATOMIC_INITIALIZER(1) }
0055
0056 QT_END_NAMESPACE
0057
0058 #endif