Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qbasicatomic.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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