Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:35

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QREFCOUNT_H
0005 #define QREFCOUNT_H
0006 
0007 #include <QtCore/qatomic.h>
0008 
0009 QT_BEGIN_NAMESPACE
0010 
0011 
0012 namespace QtPrivate
0013 {
0014 
0015 class RefCount
0016 {
0017 public:
0018     inline bool ref() noexcept {
0019         int count = atomic.loadRelaxed();
0020         if (count != -1) // !isStatic
0021             atomic.ref();
0022         return true;
0023     }
0024 
0025     inline bool deref() noexcept {
0026         int count = atomic.loadRelaxed();
0027         if (count == -1) // isStatic
0028             return true;
0029         return atomic.deref();
0030     }
0031 
0032     bool isStatic() const noexcept
0033     {
0034         // Persistent object, never deleted
0035         return atomic.loadRelaxed() == -1;
0036     }
0037 
0038     bool isShared() const noexcept
0039     {
0040         int count = atomic.loadRelaxed();
0041         return (count != 1) && (count != 0);
0042     }
0043 
0044     void initializeOwned() noexcept { atomic.storeRelaxed(1); }
0045     void initializeUnsharable() noexcept { atomic.storeRelaxed(0); }
0046 
0047     QBasicAtomicInt atomic;
0048 };
0049 
0050 }
0051 
0052 #define Q_REFCOUNT_INITIALIZE_STATIC { Q_BASIC_ATOMIC_INITIALIZER(-1) }
0053 
0054 QT_END_NAMESPACE
0055 
0056 #endif