parisc-atomic
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Wed, 9 Nov 2016 16:50:49 +0000 (16:50 +0000)
committerLisandro Damián Nicanor Pérez Meyer <lisandro@debian.org>
Wed, 9 Nov 2016 16:50:49 +0000 (16:50 +0000)
Gbp-Pq: Name parisc-atomic.patch

src/corelib/arch/parisc/arch.pri
src/corelib/arch/qatomic_parisc.h
src/corelib/thread/qatomic.h
src/corelib/thread/qbasicatomic.h

index fab2897f04dc95109966e55edc8d546b3a9f0a60..509ab84c252579115c14287dd5fe66e8a84a30ba 100644 (file)
@@ -1,5 +1,3 @@
 #
 # HP PA-RISC architecture
 #
-SOURCES += $$QT_ARCH_CPP/q_ldcw.s \
-          $$QT_ARCH_CPP/qatomic_parisc.cpp
index c444e75de8715b5e58f699649f5951d11b8403a1..b520e04f8adcd618f41ec0fe01f29d156eeab2b9 100644 (file)
@@ -101,41 +101,19 @@ template <typename T>
 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddWaitFree()
 { return false; }
 
-extern "C" {
-    Q_CORE_EXPORT void q_atomic_lock(int *lock);
-    Q_CORE_EXPORT void q_atomic_unlock(int *lock);
-}
-
-// Reference counting
-
 inline bool QBasicAtomicInt::ref()
 {
-    q_atomic_lock(_q_lock);
-    bool ret = (++_q_value != 0);
-    q_atomic_unlock(_q_lock);
-    return ret;
+    return __sync_add_and_fetch(&_q_value, 1);
 }
 
 inline bool QBasicAtomicInt::deref()
 {
-    q_atomic_lock(_q_lock);
-    bool ret = (--_q_value != 0);
-    q_atomic_unlock(_q_lock);
-    return ret;
+    return __sync_sub_and_fetch(&_q_value, 1);
 }
 
-// Test-and-set for integers
-
 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
 {
-    q_atomic_lock(_q_lock);
-    if (_q_value == expectedValue) {
-        _q_value = newValue;
-        q_atomic_unlock(_q_lock);
-        return true;
-    }
-    q_atomic_unlock(_q_lock);
-    return false;
+    return __sync_bool_compare_and_swap(&_q_value, expectedValue, newValue);
 }
 
 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
@@ -153,15 +131,9 @@ inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
     return testAndSetOrdered(expectedValue, newValue);
 }
 
-// Fetch-and-store for integers
-
 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
 {
-    q_atomic_lock(_q_lock);
-    int returnValue = _q_value;
-    _q_value = newValue;
-    q_atomic_unlock(_q_lock);
-    return returnValue;
+    return __sync_lock_test_and_set(&_q_value, newValue);
 }
 
 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
@@ -179,15 +151,9 @@ inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
     return fetchAndStoreOrdered(newValue);
 }
 
-// Fetch-and-add for integers
-
 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
 {
-    q_atomic_lock(_q_lock);
-    int originalValue = _q_value;
-    _q_value += valueToAdd;
-    q_atomic_unlock(_q_lock);
-    return originalValue;
+    return __sync_fetch_and_add(&_q_value, valueToAdd);
 }
 
 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
@@ -205,19 +171,10 @@ inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
     return fetchAndAddOrdered(valueToAdd);
 }
 
-// Test and set for pointers
-
 template <typename T>
 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
 {
-    q_atomic_lock(_q_lock);
-    if (_q_value == expectedValue) {
-        _q_value = newValue;
-        q_atomic_unlock(_q_lock);
-        return true;
-    }
-    q_atomic_unlock(_q_lock);
-    return false;
+    return __sync_bool_compare_and_swap(&_q_value, expectedValue, newValue);
 }
 
 template <typename T>
@@ -238,16 +195,10 @@ Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValu
     return testAndSetOrdered(expectedValue, newValue);
 }
 
-// Fetch and store for pointers
-
 template <typename T>
 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreOrdered(T *newValue)
 {
-    q_atomic_lock(_q_lock);
-    T *returnValue = (_q_value);
-    _q_value = newValue;
-    q_atomic_unlock(_q_lock);
-    return returnValue;
+    return __sync_lock_test_and_set(&_q_value, newValue);
 }
 
 template <typename T>
@@ -268,16 +219,10 @@ Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
     return fetchAndStoreOrdered(newValue);
 }
 
-// Fetch and add for pointers
-
 template <typename T>
 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
 {
-    q_atomic_lock(_q_lock);
-    T *returnValue = (_q_value);
-    _q_value += valueToAdd;
-    q_atomic_unlock(_q_lock);
-    return returnValue;
+    return __sync_fetch_and_add(&_q_value, valueToAdd * sizeof(T));
 }
 
 template <typename T>
index b8c0718b2885e69c2dfb3fa4a1ffa10f62932774..7bb0809d7497d40b52ea963698648cdd5ad0bb0e 100644 (file)
@@ -57,16 +57,10 @@ class Q_CORE_EXPORT QAtomicInt : public QBasicAtomicInt
 public:
     inline QAtomicInt(int value = 0)
     {
-#ifdef QT_ARCH_PARISC
-        this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1;
-#endif
         _q_value = value;
     }
     inline QAtomicInt(const QAtomicInt &other)
     {
-#ifdef QT_ARCH_PARISC
-        this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1;
-#endif
         _q_value = other._q_value;
     }
 
@@ -127,16 +121,10 @@ class QAtomicPointer : public QBasicAtomicPointer<T>
 public:
     inline QAtomicPointer(T *value = 0)
     {
-#ifdef QT_ARCH_PARISC
-        this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1;
-#endif
         QBasicAtomicPointer<T>::_q_value = value;
     }
     inline QAtomicPointer(const QAtomicPointer<T> &other)
     {
-#ifdef QT_ARCH_PARISC
-        this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1;
-#endif
         QBasicAtomicPointer<T>::_q_value = other._q_value;
     }
 
index ed04f94779bc739bc246dc9ddd260725c92fd9cf..8238f89183ad73fe528cc3d1b4dd49ce4fb3d9ed 100644 (file)
@@ -53,9 +53,6 @@ QT_MODULE(Core)
 class Q_CORE_EXPORT QBasicAtomicInt
 {
 public:
-#ifdef QT_ARCH_PARISC
-    int _q_lock[4];
-#endif
 #if defined(QT_ARCH_WINDOWS) || defined(QT_ARCH_WINDOWSCE)
     union { // needed for Q_BASIC_ATOMIC_INITIALIZER
         volatile long _q_value;
@@ -87,9 +84,6 @@ public:
 
     inline QBasicAtomicInt &operator=(int value)
     {
-#ifdef QT_ARCH_PARISC
-        this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1;
-#endif
         _q_value = value;
         return *this;
     }
@@ -131,9 +125,6 @@ template <typename T>
 class QBasicAtomicPointer
 {
 public:
-#ifdef QT_ARCH_PARISC
-    int _q_lock[4];
-#endif
 #if defined(QT_ARCH_WINDOWS) || defined(QT_ARCH_WINDOWSCE)
     union {
         T * volatile _q_value;
@@ -176,9 +167,6 @@ public:
 
     inline QBasicAtomicPointer<T> &operator=(T *value)
     {
-#ifdef QT_ARCH_PARISC
-        this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1;
-#endif
         _q_value = value;
         return *this;
     }
@@ -210,9 +198,7 @@ public:
     T *fetchAndAddOrdered(qptrdiff valueToAdd);
 };
 
-#ifdef QT_ARCH_PARISC
-#  define Q_BASIC_ATOMIC_INITIALIZER(a) {{-1,-1,-1,-1},(a)}
-#elif defined(QT_ARCH_WINDOWS) || defined(QT_ARCH_WINDOWSCE)
+#if defined(QT_ARCH_WINDOWS) || defined(QT_ARCH_WINDOWSCE)
 #  define Q_BASIC_ATOMIC_INITIALIZER(a) { {(a)} }
 #else
 #  define Q_BASIC_ATOMIC_INITIALIZER(a) { (a) }