summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago@kde.org>2011-07-31 18:25:24 -0300
committerQt by Nokia <qt-info@nokia.com>2012-01-24 01:08:24 +0100
commit161d5eb3239b52e6f19942721491f2632305e426 (patch)
tree5d3594cb27c8c291d5a0eaef16eaef16b4b3e79d
parent1831abb5bbcb520ffcb329fa67bf4d4405eb2ab4 (diff)
Port the bootstrap atomics to the new QBasicAtomic architecture
The code is now much simpler and much more complete. Now the bootstrap atomics (which aren't atomic at all) contain the full set of operations. The only integer supported is int, but all others would work too. Change-Id: Id99f07818f9da059c4ff02520f9cbf2d1a71a514 Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/arch/qatomic_bootstrap.h95
-rw-r--r--src/corelib/thread/qbasicatomic.h5
-rw-r--r--src/corelib/thread/qoldbasicatomic.h4
3 files changed, 42 insertions, 62 deletions
diff --git a/src/corelib/arch/qatomic_bootstrap.h b/src/corelib/arch/qatomic_bootstrap.h
index 901611c592..4115b43444 100644
--- a/src/corelib/arch/qatomic_bootstrap.h
+++ b/src/corelib/arch/qatomic_bootstrap.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Thiago Macieira <thiago@kde.org>
** All rights reserved.
** Contact: http://www.qt-project.org/
**
@@ -42,76 +43,54 @@
#ifndef QATOMIC_BOOTSTRAP_H
#define QATOMIC_BOOTSTRAP_H
+#include <QtCore/qgenericatomic.h>
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-inline bool QBasicAtomicInt::ref()
-{
- return ++_q_value != 0;
-}
+#if 0
+#pragma qt_sync_stop_processing
+#endif
-inline bool QBasicAtomicInt::deref()
+template<> struct QAtomicIntegerTraits<int> { enum { IsInteger = 1 }; };
+template <typename T> struct QAtomicOps: QGenericAtomicOps<QAtomicOps<T> >
{
- return --_q_value != 0;
-}
+ typedef T Type;
-inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
-{
- if (_q_value == expectedValue) {
- _q_value = newValue;
- return true;
+ static bool ref(T &_q_value)
+ {
+ return ++_q_value != 0;
+ }
+ static bool deref(T &_q_value)
+ {
+ return --_q_value != 0;
}
- return false;
-}
-
-inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
-{
- return testAndSetOrdered(expectedValue, newValue);
-}
-
-inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
-{
- return testAndSetOrdered(expectedValue, newValue);
-}
-
-inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
-{
- return testAndSetOrdered(expectedValue, newValue);
-}
-
-inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
-{
- int returnValue = _q_value;
- _q_value += valueToAdd;
- return returnValue;
-}
-
-inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
-{
- return fetchAndAddOrdered(valueToAdd);
-}
-
-inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
-{
- return fetchAndAddOrdered(valueToAdd);
-}
-
-inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
-{
- return fetchAndAddOrdered(valueToAdd);
-}
+ static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue)
+ {
+ if (_q_value == expectedValue) {
+ _q_value = newValue;
+ return true;
+ }
+ return false;
+ }
-template <typename T>
-Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
-{
- if (_q_value == expectedValue) {
+ static T fetchAndStoreRelaxed(T &_q_value, T newValue)
+ {
+ T tmp = _q_value;
_q_value = newValue;
- return true;
+ return tmp;
+ }
+
+ static
+ T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd)
+ {
+ T returnValue = _q_value;
+ _q_value += valueToAdd;
+ return returnValue;
}
- return false;
-}
+};
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h
index 91df7501a0..fd32c55ed0 100644
--- a/src/corelib/thread/qbasicatomic.h
+++ b/src/corelib/thread/qbasicatomic.h
@@ -43,7 +43,11 @@
#include <QtCore/qglobal.h>
+#if defined(QT_MOC) || defined(QT_BUILD_QMAKE) || defined(QT_RCC) || defined(QT_UIC) || defined(QT_BOOTSTRAPPED)
+# include <QtCore/qatomic_bootstrap.h>
+#else
# define QT_OLD_ATOMICS
+#endif
#ifdef QT_OLD_ATOMICS
# include "qoldbasicatomic.h"
@@ -207,4 +211,5 @@ QT_END_HEADER
#endif // QT_OLD_ATOMICS
+
#endif // QBASIC_ATOMIC
diff --git a/src/corelib/thread/qoldbasicatomic.h b/src/corelib/thread/qoldbasicatomic.h
index 0842bf5f4c..96feb2e491 100644
--- a/src/corelib/thread/qoldbasicatomic.h
+++ b/src/corelib/thread/qoldbasicatomic.h
@@ -171,10 +171,6 @@ public:
QT_END_NAMESPACE
QT_END_HEADER
-#if defined(QT_MOC) || defined(QT_BUILD_QMAKE) || defined(QT_RCC) || defined(QT_UIC) || defined(QT_BOOTSTRAPPED)
-# include <QtCore/qatomic_bootstrap.h>
-#else
# include <QtCore/qatomic_arch.h>
-#endif
#endif // QBASIC_ATOMIC