summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qatomic.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/thread/qatomic.h')
-rw-r--r--src/corelib/thread/qatomic.h115
1 files changed, 25 insertions, 90 deletions
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h
index aa57ddc610..7fe5ac69b9 100644
--- a/src/corelib/thread/qatomic.h
+++ b/src/corelib/thread/qatomic.h
@@ -1,44 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qglobal.h>
+// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QATOMIC_H
#define QATOMIC_H
@@ -50,29 +12,16 @@ QT_BEGIN_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wextra")
-#ifdef Q_CLANG_QDOC
-# undef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
-#endif
-
// High-level atomic integer operations
template <typename T>
class QAtomicInteger : public QBasicAtomicInteger<T>
{
public:
// Non-atomic API
-#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
constexpr QAtomicInteger(T value = 0) noexcept : QBasicAtomicInteger<T>(value) {}
-#else
- inline QAtomicInteger(T value = 0) noexcept
- {
- this->_q_value = value;
- }
-#endif
inline QAtomicInteger(const QAtomicInteger &other) noexcept
-#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
: QBasicAtomicInteger<T>()
-#endif
{
this->storeRelease(other.loadAcquire());
}
@@ -83,41 +32,44 @@ public:
return *this;
}
-#ifdef Q_CLANG_QDOC
- T load() const;
+#ifdef Q_QDOC
T loadRelaxed() const;
T loadAcquire() const;
- void store(T newValue);
void storeRelaxed(T newValue);
void storeRelease(T newValue);
operator T() const;
QAtomicInteger &operator=(T);
- static Q_DECL_CONSTEXPR bool isReferenceCountingNative();
- static Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree();
+ static constexpr bool isReferenceCountingNative();
+ static constexpr bool isReferenceCountingWaitFree();
bool ref();
bool deref();
- static Q_DECL_CONSTEXPR bool isTestAndSetNative();
- static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree();
+ static constexpr bool isTestAndSetNative();
+ static constexpr bool isTestAndSetWaitFree();
bool testAndSetRelaxed(T expectedValue, T newValue);
bool testAndSetAcquire(T expectedValue, T newValue);
bool testAndSetRelease(T expectedValue, T newValue);
bool testAndSetOrdered(T expectedValue, T newValue);
- static Q_DECL_CONSTEXPR bool isFetchAndStoreNative();
- static Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree();
+ bool testAndSetRelaxed(T expectedValue, T newValue, T &currentValue);
+ bool testAndSetAcquire(T expectedValue, T newValue, T &currentValue);
+ bool testAndSetRelease(T expectedValue, T newValue, T &currentValue);
+ bool testAndSetOrdered(T expectedValue, T newValue, T &currentValue);
+
+ static constexpr bool isFetchAndStoreNative();
+ static constexpr bool isFetchAndStoreWaitFree();
T fetchAndStoreRelaxed(T newValue);
T fetchAndStoreAcquire(T newValue);
T fetchAndStoreRelease(T newValue);
T fetchAndStoreOrdered(T newValue);
- static Q_DECL_CONSTEXPR bool isFetchAndAddNative();
- static Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree();
+ static constexpr bool isFetchAndAddNative();
+ static constexpr bool isFetchAndAddWaitFree();
T fetchAndAddRelaxed(T valueToAdd);
T fetchAndAddAcquire(T valueToAdd);
@@ -162,10 +114,7 @@ public:
// Non-atomic API
// We could use QT_COMPILER_INHERITING_CONSTRUCTORS, but we need only one;
// the implicit definition for all the others is fine.
-#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
- constexpr
-#endif
- QAtomicInt(int value = 0) noexcept : QAtomicInteger<int>(value) {}
+ constexpr QAtomicInt(int value = 0) noexcept : QAtomicInteger<int>(value) {}
};
// High-level atomic pointer operations
@@ -173,18 +122,10 @@ template <typename T>
class QAtomicPointer : public QBasicAtomicPointer<T>
{
public:
-#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
constexpr QAtomicPointer(T *value = nullptr) noexcept : QBasicAtomicPointer<T>(value) {}
-#else
- inline QAtomicPointer(T *value = nullptr) noexcept
- {
- this->storeRelaxed(value);
- }
-#endif
+
inline QAtomicPointer(const QAtomicPointer<T> &other) noexcept
-#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
: QBasicAtomicPointer<T>()
-#endif
{
this->storeRelease(other.loadAcquire());
}
@@ -196,31 +137,29 @@ public:
}
#ifdef Q_QDOC
- T *load() const;
T *loadAcquire() const;
T *loadRelaxed() const;
- void store(T *newValue);
void storeRelaxed(T *newValue);
void storeRelease(T *newValue);
- static Q_DECL_CONSTEXPR bool isTestAndSetNative();
- static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree();
+ static constexpr bool isTestAndSetNative();
+ static constexpr bool isTestAndSetWaitFree();
bool testAndSetRelaxed(T *expectedValue, T *newValue);
bool testAndSetAcquire(T *expectedValue, T *newValue);
bool testAndSetRelease(T *expectedValue, T *newValue);
bool testAndSetOrdered(T *expectedValue, T *newValue);
- static Q_DECL_CONSTEXPR bool isFetchAndStoreNative();
- static Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree();
+ static constexpr bool isFetchAndStoreNative();
+ static constexpr bool isFetchAndStoreWaitFree();
T *fetchAndStoreRelaxed(T *newValue);
T *fetchAndStoreAcquire(T *newValue);
T *fetchAndStoreRelease(T *newValue);
T *fetchAndStoreOrdered(T *newValue);
- static Q_DECL_CONSTEXPR bool isFetchAndAddNative();
- static Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree();
+ static constexpr bool isFetchAndAddNative();
+ static constexpr bool isFetchAndAddWaitFree();
T *fetchAndAddRelaxed(qptrdiff valueToAdd);
T *fetchAndAddAcquire(qptrdiff valueToAdd);
@@ -231,10 +170,6 @@ public:
QT_WARNING_POP
-#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
-# undef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
-#endif
-
/*!
This is a helper for the assignment operators of implicitly
shared classes. Your assignment operator should look like this: