Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 08:27:06

0001 // Copyright (C) 2011 Thiago Macieira <thiago@kde.org>
0002 // Copyright (C) 2018 Intel Corporation.
0003 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0004 // Qt-Security score:significant reason:default
0005 
0006 #ifndef QBASICATOMIC_H
0007 #define QBASICATOMIC_H
0008 
0009 #include <QtCore/qatomic_cxx11.h>
0010 
0011 QT_WARNING_PUSH
0012 QT_WARNING_DISABLE_MSVC(4522)
0013 
0014 QT_BEGIN_NAMESPACE
0015 
0016 #if 0
0017 // silence syncqt warnings
0018 QT_END_NAMESPACE
0019 #pragma qt_no_master_include
0020 #pragma qt_sync_stop_processing
0021 #endif
0022 
0023 template <typename T>
0024 class QBasicAtomicInteger
0025 {
0026 public:
0027     typedef T Type;
0028     typedef QAtomicOps<T> Ops;
0029     // static check that this is a valid integer
0030     static_assert(std::is_integral_v<T>, "template parameter is not an integral type");
0031     static_assert(QAtomicOpsSupport<sizeof(T)>::IsSupported, "template parameter is an integral of a size not supported on this platform");
0032 
0033     typename Ops::Type _q_value;
0034 
0035     // Everything below is either implemented in ../arch/qatomic_XXX.h or (as
0036     // fallback) in qgenericatomic.h
0037     T loadRelaxed() const noexcept { return Ops::loadRelaxed(_q_value); }
0038     void storeRelaxed(T newValue) noexcept { Ops::storeRelaxed(_q_value, newValue); }
0039 
0040     T loadAcquire() const noexcept { return Ops::loadAcquire(_q_value); }
0041     void storeRelease(T newValue) noexcept { Ops::storeRelease(_q_value, newValue); }
0042     operator T() const noexcept { return loadAcquire(); }
0043     T operator=(T newValue) noexcept { storeRelease(newValue); return newValue; }
0044 
0045     static constexpr bool isReferenceCountingNative() noexcept { return Ops::isReferenceCountingNative(); }
0046     static constexpr bool isReferenceCountingWaitFree() noexcept { return Ops::isReferenceCountingWaitFree(); }
0047 
0048     bool ref() noexcept { return Ops::ref(_q_value); }
0049     bool deref() noexcept { return Ops::deref(_q_value); }
0050 
0051     static constexpr bool isTestAndSetNative() noexcept { return Ops::isTestAndSetNative(); }
0052     static constexpr bool isTestAndSetWaitFree() noexcept { return Ops::isTestAndSetWaitFree(); }
0053 
0054     bool testAndSetRelaxed(T expectedValue, T newValue) noexcept
0055     { return Ops::testAndSetRelaxed(_q_value, expectedValue, newValue); }
0056     bool testAndSetAcquire(T expectedValue, T newValue) noexcept
0057     { return Ops::testAndSetAcquire(_q_value, expectedValue, newValue); }
0058     bool testAndSetRelease(T expectedValue, T newValue) noexcept
0059     { return Ops::testAndSetRelease(_q_value, expectedValue, newValue); }
0060     bool testAndSetOrdered(T expectedValue, T newValue) noexcept
0061     { return Ops::testAndSetOrdered(_q_value, expectedValue, newValue); }
0062 
0063     bool testAndSetRelaxed(T expectedValue, T newValue, T &currentValue) noexcept
0064     { return Ops::testAndSetRelaxed(_q_value, expectedValue, newValue, &currentValue); }
0065     bool testAndSetAcquire(T expectedValue, T newValue, T &currentValue) noexcept
0066     { return Ops::testAndSetAcquire(_q_value, expectedValue, newValue, &currentValue); }
0067     bool testAndSetRelease(T expectedValue, T newValue, T &currentValue) noexcept
0068     { return Ops::testAndSetRelease(_q_value, expectedValue, newValue, &currentValue); }
0069     bool testAndSetOrdered(T expectedValue, T newValue, T &currentValue) noexcept
0070     { return Ops::testAndSetOrdered(_q_value, expectedValue, newValue, &currentValue); }
0071 
0072     static constexpr bool isFetchAndStoreNative() noexcept { return Ops::isFetchAndStoreNative(); }
0073     static constexpr bool isFetchAndStoreWaitFree() noexcept { return Ops::isFetchAndStoreWaitFree(); }
0074 
0075     T fetchAndStoreRelaxed(T newValue) noexcept
0076     { return Ops::fetchAndStoreRelaxed(_q_value, newValue); }
0077     T fetchAndStoreAcquire(T newValue) noexcept
0078     { return Ops::fetchAndStoreAcquire(_q_value, newValue); }
0079     T fetchAndStoreRelease(T newValue) noexcept
0080     { return Ops::fetchAndStoreRelease(_q_value, newValue); }
0081     T fetchAndStoreOrdered(T newValue) noexcept
0082     { return Ops::fetchAndStoreOrdered(_q_value, newValue); }
0083 
0084     static constexpr bool isFetchAndAddNative() noexcept { return Ops::isFetchAndAddNative(); }
0085     static constexpr bool isFetchAndAddWaitFree() noexcept { return Ops::isFetchAndAddWaitFree(); }
0086 
0087     T fetchAndAddRelaxed(T valueToAdd) noexcept
0088     { return Ops::fetchAndAddRelaxed(_q_value, valueToAdd); }
0089     T fetchAndAddAcquire(T valueToAdd) noexcept
0090     { return Ops::fetchAndAddAcquire(_q_value, valueToAdd); }
0091     T fetchAndAddRelease(T valueToAdd) noexcept
0092     { return Ops::fetchAndAddRelease(_q_value, valueToAdd); }
0093     T fetchAndAddOrdered(T valueToAdd) noexcept
0094     { return Ops::fetchAndAddOrdered(_q_value, valueToAdd); }
0095 
0096     T fetchAndSubRelaxed(T valueToAdd) noexcept
0097     { return Ops::fetchAndSubRelaxed(_q_value, valueToAdd); }
0098     T fetchAndSubAcquire(T valueToAdd) noexcept
0099     { return Ops::fetchAndSubAcquire(_q_value, valueToAdd); }
0100     T fetchAndSubRelease(T valueToAdd) noexcept
0101     { return Ops::fetchAndSubRelease(_q_value, valueToAdd); }
0102     T fetchAndSubOrdered(T valueToAdd) noexcept
0103     { return Ops::fetchAndSubOrdered(_q_value, valueToAdd); }
0104 
0105     T fetchAndAndRelaxed(T valueToAdd) noexcept
0106     { return Ops::fetchAndAndRelaxed(_q_value, valueToAdd); }
0107     T fetchAndAndAcquire(T valueToAdd) noexcept
0108     { return Ops::fetchAndAndAcquire(_q_value, valueToAdd); }
0109     T fetchAndAndRelease(T valueToAdd) noexcept
0110     { return Ops::fetchAndAndRelease(_q_value, valueToAdd); }
0111     T fetchAndAndOrdered(T valueToAdd) noexcept
0112     { return Ops::fetchAndAndOrdered(_q_value, valueToAdd); }
0113 
0114     T fetchAndOrRelaxed(T valueToAdd) noexcept
0115     { return Ops::fetchAndOrRelaxed(_q_value, valueToAdd); }
0116     T fetchAndOrAcquire(T valueToAdd) noexcept
0117     { return Ops::fetchAndOrAcquire(_q_value, valueToAdd); }
0118     T fetchAndOrRelease(T valueToAdd) noexcept
0119     { return Ops::fetchAndOrRelease(_q_value, valueToAdd); }
0120     T fetchAndOrOrdered(T valueToAdd) noexcept
0121     { return Ops::fetchAndOrOrdered(_q_value, valueToAdd); }
0122 
0123     T fetchAndXorRelaxed(T valueToAdd) noexcept
0124     { return Ops::fetchAndXorRelaxed(_q_value, valueToAdd); }
0125     T fetchAndXorAcquire(T valueToAdd) noexcept
0126     { return Ops::fetchAndXorAcquire(_q_value, valueToAdd); }
0127     T fetchAndXorRelease(T valueToAdd) noexcept
0128     { return Ops::fetchAndXorRelease(_q_value, valueToAdd); }
0129     T fetchAndXorOrdered(T valueToAdd) noexcept
0130     { return Ops::fetchAndXorOrdered(_q_value, valueToAdd); }
0131 
0132     T operator++() noexcept
0133     { return fetchAndAddOrdered(1) + 1; }
0134     T operator++(int) noexcept
0135     { return fetchAndAddOrdered(1); }
0136     T operator--() noexcept
0137     { return fetchAndSubOrdered(1) - 1; }
0138     T operator--(int) noexcept
0139     { return fetchAndSubOrdered(1); }
0140 
0141     T operator+=(T v) noexcept
0142     { return fetchAndAddOrdered(v) + v; }
0143     T operator-=(T v) noexcept
0144     { return fetchAndSubOrdered(v) - v; }
0145     T operator&=(T v) noexcept
0146     { return fetchAndAndOrdered(v) & v; }
0147     T operator|=(T v) noexcept
0148     { return fetchAndOrOrdered(v) | v; }
0149     T operator^=(T v) noexcept
0150     { return fetchAndXorOrdered(v) ^ v; }
0151 
0152 
0153     QBasicAtomicInteger() = default;
0154     constexpr QBasicAtomicInteger(T value) noexcept : _q_value(value) {}
0155     QBasicAtomicInteger(const QBasicAtomicInteger &) = delete;
0156     QBasicAtomicInteger &operator=(const QBasicAtomicInteger &) = delete;
0157     QBasicAtomicInteger &operator=(const QBasicAtomicInteger &) volatile = delete;
0158 };
0159 typedef QBasicAtomicInteger<int> QBasicAtomicInt;
0160 
0161 template <typename X>
0162 class QBasicAtomicPointer
0163 {
0164 public:
0165     typedef X *Type;
0166     typedef QAtomicOps<Type> Ops;
0167     typedef typename Ops::Type AtomicType;
0168 
0169     AtomicType _q_value;
0170 
0171     Type loadRelaxed() const noexcept { return Ops::loadRelaxed(_q_value); }
0172     void storeRelaxed(Type newValue) noexcept { Ops::storeRelaxed(_q_value, newValue); }
0173 
0174     operator Type() const noexcept { return loadAcquire(); }
0175     Type operator=(Type newValue) noexcept { storeRelease(newValue); return newValue; }
0176 
0177     // Atomic API, implemented in qatomic_XXX.h
0178     Type loadAcquire() const noexcept { return Ops::loadAcquire(_q_value); }
0179     void storeRelease(Type newValue) noexcept { Ops::storeRelease(_q_value, newValue); }
0180 
0181     static constexpr bool isTestAndSetNative() noexcept { return Ops::isTestAndSetNative(); }
0182     static constexpr bool isTestAndSetWaitFree() noexcept { return Ops::isTestAndSetWaitFree(); }
0183 
0184     bool testAndSetRelaxed(Type expectedValue, Type newValue) noexcept
0185     { return Ops::testAndSetRelaxed(_q_value, expectedValue, newValue); }
0186     bool testAndSetAcquire(Type expectedValue, Type newValue) noexcept
0187     { return Ops::testAndSetAcquire(_q_value, expectedValue, newValue); }
0188     bool testAndSetRelease(Type expectedValue, Type newValue) noexcept
0189     { return Ops::testAndSetRelease(_q_value, expectedValue, newValue); }
0190     bool testAndSetOrdered(Type expectedValue, Type newValue) noexcept
0191     { return Ops::testAndSetOrdered(_q_value, expectedValue, newValue); }
0192 
0193     bool testAndSetRelaxed(Type expectedValue, Type newValue, Type &currentValue) noexcept
0194     { return Ops::testAndSetRelaxed(_q_value, expectedValue, newValue, &currentValue); }
0195     bool testAndSetAcquire(Type expectedValue, Type newValue, Type &currentValue) noexcept
0196     { return Ops::testAndSetAcquire(_q_value, expectedValue, newValue, &currentValue); }
0197     bool testAndSetRelease(Type expectedValue, Type newValue, Type &currentValue) noexcept
0198     { return Ops::testAndSetRelease(_q_value, expectedValue, newValue, &currentValue); }
0199     bool testAndSetOrdered(Type expectedValue, Type newValue, Type &currentValue) noexcept
0200     { return Ops::testAndSetOrdered(_q_value, expectedValue, newValue, &currentValue); }
0201 
0202     static constexpr bool isFetchAndStoreNative() noexcept { return Ops::isFetchAndStoreNative(); }
0203     static constexpr bool isFetchAndStoreWaitFree() noexcept { return Ops::isFetchAndStoreWaitFree(); }
0204 
0205     Type fetchAndStoreRelaxed(Type newValue) noexcept
0206     { return Ops::fetchAndStoreRelaxed(_q_value, newValue); }
0207     Type fetchAndStoreAcquire(Type newValue) noexcept
0208     { return Ops::fetchAndStoreAcquire(_q_value, newValue); }
0209     Type fetchAndStoreRelease(Type newValue) noexcept
0210     { return Ops::fetchAndStoreRelease(_q_value, newValue); }
0211     Type fetchAndStoreOrdered(Type newValue) noexcept
0212     { return Ops::fetchAndStoreOrdered(_q_value, newValue); }
0213 
0214     static constexpr bool isFetchAndAddNative() noexcept { return Ops::isFetchAndAddNative(); }
0215     static constexpr bool isFetchAndAddWaitFree() noexcept { return Ops::isFetchAndAddWaitFree(); }
0216 
0217     Type fetchAndAddRelaxed(qptrdiff valueToAdd) noexcept
0218     { return Ops::fetchAndAddRelaxed(_q_value, valueToAdd); }
0219     Type fetchAndAddAcquire(qptrdiff valueToAdd) noexcept
0220     { return Ops::fetchAndAddAcquire(_q_value, valueToAdd); }
0221     Type fetchAndAddRelease(qptrdiff valueToAdd) noexcept
0222     { return Ops::fetchAndAddRelease(_q_value, valueToAdd); }
0223     Type fetchAndAddOrdered(qptrdiff valueToAdd) noexcept
0224     { return Ops::fetchAndAddOrdered(_q_value, valueToAdd); }
0225 
0226     Type fetchAndSubRelaxed(qptrdiff valueToAdd) noexcept
0227     { return Ops::fetchAndSubRelaxed(_q_value, valueToAdd); }
0228     Type fetchAndSubAcquire(qptrdiff valueToAdd) noexcept
0229     { return Ops::fetchAndSubAcquire(_q_value, valueToAdd); }
0230     Type fetchAndSubRelease(qptrdiff valueToAdd) noexcept
0231     { return Ops::fetchAndSubRelease(_q_value, valueToAdd); }
0232     Type fetchAndSubOrdered(qptrdiff valueToAdd) noexcept
0233     { return Ops::fetchAndSubOrdered(_q_value, valueToAdd); }
0234 
0235     Type operator++() noexcept
0236     { return fetchAndAddOrdered(1) + 1; }
0237     Type operator++(int) noexcept
0238     { return fetchAndAddOrdered(1); }
0239     Type operator--() noexcept
0240     { return fetchAndSubOrdered(1) - 1; }
0241     Type operator--(int) noexcept
0242     { return fetchAndSubOrdered(1); }
0243     Type operator+=(qptrdiff valueToAdd) noexcept
0244     { return fetchAndAddOrdered(valueToAdd) + valueToAdd; }
0245     Type operator-=(qptrdiff valueToSub) noexcept
0246     { return fetchAndSubOrdered(valueToSub) - valueToSub; }
0247 
0248     QBasicAtomicPointer() = default;
0249     constexpr QBasicAtomicPointer(Type value) noexcept : _q_value(value) {}
0250     QBasicAtomicPointer(const QBasicAtomicPointer &) = delete;
0251     QBasicAtomicPointer &operator=(const QBasicAtomicPointer &) = delete;
0252     QBasicAtomicPointer &operator=(const QBasicAtomicPointer &) volatile = delete;
0253 };
0254 
0255 #ifndef Q_BASIC_ATOMIC_INITIALIZER
0256 #  define Q_BASIC_ATOMIC_INITIALIZER(a) { (a) }
0257 #endif
0258 
0259 QT_END_NAMESPACE
0260 
0261 QT_WARNING_POP
0262 
0263 #endif // QBASICATOMIC_H