qatomic_alpha.h
上传用户:detong
上传日期:2022-06-22
资源大小:20675k
文件大小:25k
源码类别:

系统编程

开发平台:

Unix_Linux

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
  4. ** Contact: Qt Software Information (qt-info@nokia.com)
  5. **
  6. ** This file is part of the QtCore module of the Qt Toolkit.
  7. **
  8. ** Commercial Usage
  9. ** Licensees holding valid Qt Commercial licenses may use this file in
  10. ** accordance with the Qt Commercial License Agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Nokia.
  13. **
  14. **
  15. ** GNU General Public License Usage
  16. ** Alternatively, this file may be used under the terms of the GNU
  17. ** General Public License versions 2.0 or 3.0 as published by the Free
  18. ** Software Foundation and appearing in the file LICENSE.GPL included in
  19. ** the packaging of this file.  Please review the following information
  20. ** to ensure GNU General Public Licensing requirements will be met:
  21. ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
  22. ** http://www.gnu.org/copyleft/gpl.html.  In addition, as a special
  23. ** exception, Nokia gives you certain additional rights. These rights
  24. ** are described in the Nokia Qt GPL Exception version 1.3, included in
  25. ** the file GPL_EXCEPTION.txt in this package.
  26. **
  27. ** Qt for Windows(R) Licensees
  28. ** As a special exception, Nokia, as the sole copyright holder for Qt
  29. ** Designer, grants users of the Qt/Eclipse Integration plug-in the
  30. ** right for the Qt/Eclipse Integration to link to functionality
  31. ** provided by Qt Designer and its related libraries.
  32. **
  33. ** If you are unsure which license is appropriate for your use, please
  34. ** contact the sales department at qt-sales@nokia.com.
  35. **
  36. ****************************************************************************/
  37. #ifndef QATOMIC_ALPHA_H
  38. #define QATOMIC_ALPHA_H
  39. QT_BEGIN_HEADER
  40. QT_BEGIN_NAMESPACE
  41. #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_ALWAYS_NATIVE
  42. inline bool QBasicAtomicInt::isReferenceCountingNative()
  43. { return true; }
  44. inline bool QBasicAtomicInt::isReferenceCountingWaitFree()
  45. { return false; }
  46. #define Q_ATOMIC_INT_TEST_AND_SET_IS_ALWAYS_NATIVE
  47. inline bool QBasicAtomicInt::isTestAndSetNative()
  48. { return true; }
  49. inline bool QBasicAtomicInt::isTestAndSetWaitFree()
  50. { return false; }
  51. #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_ALWAYS_NATIVE
  52. inline bool QBasicAtomicInt::isFetchAndStoreNative()
  53. { return true; }
  54. inline bool QBasicAtomicInt::isFetchAndStoreWaitFree()
  55. { return false; }
  56. #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_ALWAYS_NATIVE
  57. inline bool QBasicAtomicInt::isFetchAndAddNative()
  58. { return true; }
  59. inline bool QBasicAtomicInt::isFetchAndAddWaitFree()
  60. { return false; }
  61. #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_ALWAYS_NATIVE
  62. template <typename T>
  63. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetNative()
  64. { return true; }
  65. template <typename T>
  66. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetWaitFree()
  67. { return false; }
  68. #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_ALWAYS_NATIVE
  69. template <typename T>
  70. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreNative()
  71. { return true; }
  72. template <typename T>
  73. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreWaitFree()
  74. { return false; }
  75. #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_ALWAYS_NATIVE
  76. template <typename T>
  77. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddNative()
  78. { return true; }
  79. template <typename T>
  80. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddWaitFree()
  81. { return false; }
  82. #if defined(Q_CC_GNU)
  83. inline bool QBasicAtomicInt::ref()
  84. {
  85.     register int old, tmp;
  86.     asm volatile("1:n"
  87.                  "ldl_l %0,%2n"   /* old=*ptr;                               */
  88.                  "addl  %0,1,%1n" /* tmp=old+1;                              */
  89.                  "stl_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  90.                  "beq   %1,2fn"   /* if (tmp == 0) goto 2;                   */
  91.                  "br    3fn"      /* goto 3;                                 */
  92.                  "2: br 1bn"      /* goto 1;                                 */
  93.                  "3:n"
  94.                  : "=&r" (old), "=&r" (tmp), "+m"(_q_value)
  95.                  :
  96.                  : "memory");
  97.     return old != -1;
  98. }
  99. inline bool QBasicAtomicInt::deref()
  100. {
  101.     register int old, tmp;
  102.     asm volatile("1:n"
  103.                  "ldl_l %0,%2n"   /* old=*ptr;                               */
  104.                  "subl  %0,1,%1n" /* tmp=old-1;                              */
  105.                  "stl_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  106.                  "beq   %1,2fn"   /* if (tmp==0) goto 2;                     */
  107.                  "br    3fn"      /* goto 3;                                 */
  108.                  "2: br 1bn"      /* goto 1;                                 */
  109.                  "3:n"
  110.                  : "=&r" (old), "=&r" (tmp), "+m"(_q_value)
  111.                  :
  112.                  : "memory");
  113.     return old != 1;
  114. }
  115. inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
  116. {
  117.     register int ret;
  118.     asm volatile("1:n"
  119.                  "ldl_l %0,%1n"   /* ret=*ptr;                               */
  120.                  "cmpeq %0,%2,%0n"/* if (ret==expected) ret=0; else ret=1;   */
  121.                  "beq   %0,3fn"   /* if (ret==0) goto 3;                     */
  122.                  "mov   %3,%0n"   /* ret=newval;                             */
  123.                  "stl_c %0,%1n"   /* if ((*ptr=ret)!=ret) ret=0; else ret=1; */
  124.                  "beq   %0,2fn"   /* if (ret==0) goto 2;                     */
  125.                  "br    3fn"      /* goto 3;                                 */
  126.                  "2: br 1bn"      /* goto 1;                                 */
  127.                  "3:n"
  128.                  : "=&r" (ret), "+m" (_q_value)
  129.                  : "r" (expectedValue), "r" (newValue)
  130.                  : "memory");
  131.     return ret != 0;
  132. }
  133. inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
  134. {
  135.     register int ret;
  136.     asm volatile("1:n"
  137.                  "ldl_l %0,%1n"   /* ret=*ptr;                               */
  138.                  "cmpeq %0,%2,%0n"/* if (ret==expected) ret=0; else ret=1;   */
  139.                  "beq   %0,3fn"   /* if (ret==0) goto 3;                     */
  140.                  "mov   %3,%0n"   /* ret=newval;                             */
  141.                  "stl_c %0,%1n"   /* if ((*ptr=ret)!=ret) ret=0; else ret=1; */
  142.                  "beq   %0,2fn"   /* if (ret==0) goto 2;                     */
  143.                  "br    3fn"      /* goto 3;                                 */
  144.                  "2: br 1bn"      /* goto 1;                                 */
  145.                  "3:n"
  146.                  "mbn"
  147.                  : "=&r" (ret), "+m" (_q_value)
  148.                  : "r" (expectedValue), "r" (newValue)
  149.                  : "memory");
  150.     return ret != 0;
  151. }
  152. inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
  153. {
  154.     register int ret;
  155.     asm volatile("mbn"
  156.                  "1:n"
  157.                  "ldl_l %0,%1n"   /* ret=*ptr;                               */
  158.                  "cmpeq %0,%2,%0n"/* if (ret==expected) ret=0; else ret=1;   */
  159.                  "beq   %0,3fn"   /* if (ret==0) goto 3;                     */
  160.                  "mov   %3,%0n"   /* ret=newval;                             */
  161.                  "stl_c %0,%1n"   /* if ((*ptr=ret)!=ret) ret=0; else ret=1; */
  162.                  "beq   %0,2fn"   /* if (ret==0) goto 2;                     */
  163.                  "br    3fn"      /* goto 3;                                 */
  164.                  "2: br 1bn"      /* goto 1;                                 */
  165.                  "3:n"
  166.                  : "=&r" (ret), "+m" (_q_value)
  167.                  : "r" (expectedValue), "r" (newValue)
  168.                  : "memory");
  169.     return ret != 0;
  170. }
  171. inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
  172. {
  173.     register int old, tmp;
  174.     asm volatile("1:n"
  175.                  "ldl_l %0,%2n"   /* old=*ptr;                               */
  176.                  "mov   %3,%1n"   /* tmp=newval;                             */
  177.                  "stl_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  178.                  "beq   %1,2fn"   /* if (tmp==0) goto 2;                     */
  179.                  "br    3fn"      /* goto 3;                                 */
  180.                  "2: br 1bn"      /* goto 1;                                 */
  181.                  "3:n"
  182.                  : "=&r" (old), "=&r" (tmp), "+m" (_q_value)
  183.                  : "r" (newValue)
  184.                  : "memory");
  185.     return old;
  186. }
  187. inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
  188. {
  189.     register int old, tmp;
  190.     asm volatile("1:n"
  191.                  "ldl_l %0,%2n"   /* old=*ptr;                               */
  192.                  "mov   %3,%1n"   /* tmp=newval;                             */
  193.                  "stl_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  194.                  "beq   %1,2fn"   /* if (tmp==0) goto 2;                     */
  195.                  "br    3fn"      /* goto 3;                                 */
  196.                  "2: br 1bn"      /* goto 1;                                 */
  197.                  "3:n"
  198.                  "mbn"
  199.                  : "=&r" (old), "=&r" (tmp), "+m" (_q_value)
  200.                  : "r" (newValue)
  201.                  : "memory");
  202.     return old;
  203. }
  204. inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
  205. {
  206.     register int old, tmp;
  207.     asm volatile("mbn"
  208.                  "1:n"
  209.                  "ldl_l %0,%2n"   /* old=*ptr;                               */
  210.                  "mov   %3,%1n"   /* tmp=newval;                             */
  211.                  "stl_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  212.                  "beq   %1,2fn"   /* if (tmp==0) goto 2;                     */
  213.                  "br    3fn"      /* goto 3;                                 */
  214.                  "2: br 1bn"      /* goto 1;                                 */
  215.                  "3:n"
  216.                  : "=&r" (old), "=&r" (tmp), "+m" (_q_value)
  217.                  : "r" (newValue)
  218.                  : "memory");
  219.     return old;
  220. }
  221. inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
  222. {
  223.     register int old, tmp;
  224.     asm volatile("1:n"
  225.                  "ldl_l %0,%2n"   /* old=*ptr;                               */
  226.                  "addl  %0,%3,%1n"/* tmp=old+value;                          */
  227.                  "stl_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  228.                  "beq   %1,2fn"   /* if (tmp == 0) goto 2;                   */
  229.                  "br    3fn"      /* goto 3;                                 */
  230.                  "2: br 1bn"      /* goto 1;                                 */
  231.                  "3:n"
  232.                  : "=&r" (old), "=&r" (tmp), "+m"(_q_value)
  233.                  : "r" (valueToAdd)
  234.                  : "memory");
  235.     return old;
  236. }
  237. inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
  238. {
  239.     register int old, tmp;
  240.     asm volatile("1:n"
  241.                  "ldl_l %0,%2n"   /* old=*ptr;                               */
  242.                  "addl  %0,%3,%1n"/* tmp=old+value;                          */
  243.                  "stl_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  244.                  "beq   %1,2fn"   /* if (tmp == 0) goto 2;                   */
  245.                  "br    3fn"      /* goto 3;                                 */
  246.                  "2: br 1bn"      /* goto 1;                                 */
  247.                  "3:n"
  248.                  "mbn"
  249.                  : "=&r" (old), "=&r" (tmp), "+m"(_q_value)
  250.                  : "r" (valueToAdd)
  251.                  : "memory");
  252.     return old;
  253. }
  254. inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
  255. {
  256.     register int old, tmp;
  257.     asm volatile("mbn"
  258.                  "1:n"
  259.                  "ldl_l %0,%2n"   /* old=*ptr;                               */
  260.                  "addl  %0,%3,%1n"/* tmp=old+value;                          */
  261.                  "stl_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  262.                  "beq   %1,2fn"   /* if (tmp == 0) goto 2;                   */
  263.                  "br    3fn"      /* goto 3;                                 */
  264.                  "2: br 1bn"      /* goto 1;                                 */
  265.                  "3:n"
  266.                  : "=&r" (old), "=&r" (tmp), "+m"(_q_value)
  267.                  : "r" (valueToAdd)
  268.                  : "memory");
  269.     return old;
  270. }
  271. template <typename T>
  272. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
  273. {
  274.     register void *ret;
  275.     asm volatile("1:n"
  276.                  "ldq_l %0,%1n"   /* ret=*ptr;                               */
  277.                  "cmpeq %0,%2,%0n"/* if (ret==expected) tmp=0; else tmp=1;   */
  278.                  "beq   %0,3fn"   /* if (tmp==0) goto 3;                     */
  279.                  "mov   %3,%0n"   /* tmp=newval;                             */
  280.                  "stq_c %0,%1n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  281.                  "beq   %0,2fn"   /* if (ret==0) goto 2;                     */
  282.                  "br    3fn"      /* goto 3;                                 */
  283.                  "2: br 1bn"      /* goto 1;                                 */
  284.                  "3:n"
  285.                  : "=&r" (ret), "+m" (_q_value)
  286.                  : "r" (expectedValue), "r" (newValue)
  287.                  : "memory");
  288.     return ret != 0;
  289. }
  290. template <typename T>
  291. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
  292. {
  293.     register void *ret;
  294.     asm volatile("1:n"
  295.                  "ldq_l %0,%1n"   /* ret=*ptr;                               */
  296.                  "cmpeq %0,%2,%0n"/* if (ret==expected) tmp=0; else tmp=1;   */
  297.                  "beq   %0,3fn"   /* if (tmp==0) goto 3;                     */
  298.                  "mov   %3,%0n"   /* tmp=newval;                             */
  299.                  "stq_c %0,%1n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  300.                  "beq   %0,2fn"   /* if (ret==0) goto 2;                     */
  301.                  "br    3fn"      /* goto 3;                                 */
  302.                  "2: br 1bn"      /* goto 1;                                 */
  303.                  "3:n"
  304.                  "mbn"
  305.                  : "=&r" (ret), "+m" (_q_value)
  306.                  : "r" (expectedValue), "r" (newValue)
  307.                  : "memory");
  308.     return ret != 0;
  309. }
  310. template <typename T>
  311. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
  312. {
  313.     register void *ret;
  314.     asm volatile("mbn"
  315.                  "1:n"
  316.                  "ldq_l %0,%1n"   /* ret=*ptr;                               */
  317.                  "cmpeq %0,%2,%0n"/* if (ret==expected) tmp=0; else tmp=1;   */
  318.                  "beq   %0,3fn"   /* if (tmp==0) goto 3;                     */
  319.                  "mov   %3,%0n"   /* tmp=newval;                             */
  320.                  "stq_c %0,%1n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  321.                  "beq   %0,2fn"   /* if (ret==0) goto 2;                     */
  322.                  "br    3fn"      /* goto 3;                                 */
  323.                  "2: br 1bn"      /* goto 1;                                 */
  324.                  "3:n"
  325.                  : "=&r" (ret), "+m" (_q_value)
  326.                  : "r" (expectedValue), "r" (newValue)
  327.                  : "memory");
  328.     return ret != 0;
  329. }
  330. template <typename T>
  331. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
  332. {
  333.     register void *old, *tmp;
  334.     asm volatile("1:n"
  335.                  "ldq_l %0,%2n"   /* old=*ptr;                               */
  336.                  "mov   %3,%1n"   /* tmp=newval;                             */
  337.                  "stq_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  338.                  "beq   %1,2fn"   /* if (tmp==0) goto 2;                     */
  339.                  "br    3fn"      /* goto 3;                                 */
  340.                  "2: br 1bn"      /* goto 1;                                 */
  341.                  "3:n"
  342.                  : "=&r" (old), "=&r" (tmp), "+m" (_q_value)
  343.                  : "r" (newValue)
  344.                  : "memory");
  345.     return old;
  346. }
  347. template <typename T>
  348. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
  349. {
  350.     register void *old, *tmp;
  351.     asm volatile("1:n"
  352.                  "ldq_l %0,%2n"   /* old=*ptr;                               */
  353.                  "mov   %3,%1n"   /* tmp=newval;                             */
  354.                  "stq_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  355.                  "beq   %1,2fn"   /* if (tmp==0) goto 2;                     */
  356.                  "br    3fn"      /* goto 3;                                 */
  357.                  "2: br 1bn"      /* goto 1;                                 */
  358.                  "3:n"
  359.                  "mbn"
  360.                  : "=&r" (old), "=&r" (tmp), "+m" (_q_value)
  361.                  : "r" (newValue)
  362.                  : "memory");
  363.     return old;
  364. }
  365. template <typename T>
  366. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
  367. {
  368.     register void *old, *tmp;
  369.     asm volatile("mbn"
  370.                  "1:n"
  371.                  "ldq_l %0,%2n"   /* old=*ptr;                               */
  372.                  "mov   %3,%1n"   /* tmp=newval;                             */
  373.                  "stq_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  374.                  "beq   %1,2fn"   /* if (tmp==0) goto 2;                     */
  375.                  "br    3fn"      /* goto 3;                                 */
  376.                  "2: br 1bn"      /* goto 1;                                 */
  377.                  "3:n"
  378.                  : "=&r" (old), "=&r" (tmp), "+m" (_q_value)
  379.                  : "r" (newValue)
  380.                  : "memory");
  381.     return old;
  382. }
  383. template <typename T>
  384. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
  385. {
  386.     register void *old, *tmp;
  387.     asm volatile("1:n"
  388.                  "ldq_l %0,%2n"   /* old=*ptr;                               */
  389.                  "addq  %0,%3,%1n"/* tmp=old+value;                          */
  390.                  "stq_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  391.                  "beq   %1,2fn"   /* if (tmp == 0) goto 2;                   */
  392.                  "br    3fn"      /* goto 3;                                 */
  393.                  "2: br 1bn"      /* goto 1;                                 */
  394.                  "3:n"
  395.                  : "=&r" (old), "=&r" (tmp), "+m"(_q_value)
  396.                  : "r" (valueToAdd)
  397.                  : "memory");
  398.     return reinterpret_cast<T *>(old);
  399. }
  400. template <typename T>
  401. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
  402. {
  403.     register void *old, *tmp;
  404.     asm volatile("1:n"
  405.                  "ldq_l %0,%2n"   /* old=*ptr;                               */
  406.                  "addq  %0,%3,%1n"/* tmp=old+value;                          */
  407.                  "stq_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  408.                  "beq   %1,2fn"   /* if (tmp == 0) goto 2;                   */
  409.                  "br    3fn"      /* goto 3;                                 */
  410.                  "2: br 1bn"      /* goto 1;                                 */
  411.                  "3:n"
  412.                  "mbn"
  413.                  : "=&r" (old), "=&r" (tmp), "+m"(_q_value)
  414.                  : "r" (valueToAdd)
  415.                  : "memory");
  416.     return reinterpret_cast<T *>(old);
  417. }
  418. template <typename T>
  419. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
  420. {
  421.     register void *old, *tmp;
  422.     asm volatile("mbn"
  423.                  "1:n"
  424.                  "ldq_l %0,%2n"   /* old=*ptr;                               */
  425.                  "addq  %0,%3,%1n"/* tmp=old+value;                          */
  426.                  "stq_c %1,%2n"   /* if ((*ptr=tmp)!=tmp) tmp=0; else tmp=1; */
  427.                  "beq   %1,2fn"   /* if (tmp == 0) goto 2;                   */
  428.                  "br    3fn"      /* goto 3;                                 */
  429.                  "2: br 1bn"      /* goto 1;                                 */
  430.                  "3:n"
  431.                  : "=&r" (old), "=&r" (tmp), "+m"(_q_value)
  432.                  : "r" (valueToAdd)
  433.                  : "memory");
  434.     return reinterpret_cast<T *>(old);
  435. }
  436. #else // !Q_CC_GNU
  437. extern "C" {
  438.     Q_CORE_EXPORT int q_atomic_test_and_set_int(volatile int *ptr, int expected, int newval);
  439.     Q_CORE_EXPORT int q_atomic_test_and_set_acquire_int(volatile int *ptr, int expected, int newval);
  440.     Q_CORE_EXPORT int q_atomic_test_and_set_release_int(volatile int *ptr, int expected, int newval);
  441.     Q_CORE_EXPORT int q_atomic_test_and_set_ptr(volatile void *ptr, void *expected, void *newval);
  442.     Q_CORE_EXPORT int q_atomic_increment(volatile int *ptr);
  443.     Q_CORE_EXPORT int q_atomic_decrement(volatile int *ptr);
  444.     Q_CORE_EXPORT int q_atomic_set_int(volatile int *ptr, int newval);
  445.     Q_CORE_EXPORT void *q_atomic_set_ptr(volatile void *ptr, void *newval);
  446.     Q_CORE_EXPORT int q_atomic_fetch_and_add_int(volatile int *ptr, int value);
  447.     Q_CORE_EXPORT int q_atomic_fetch_and_add_acquire_int(volatile int *ptr, int value);
  448.     Q_CORE_EXPORT int q_atomic_fetch_and_add_release_int(volatile int *ptr, int value);
  449. } // extern "C"
  450. inline bool QBasicAtomicInt::ref()
  451. {
  452.     return q_atomic_increment(&_q_value) != 0;
  453. }
  454. inline bool QBasicAtomicInt::deref()
  455. {
  456.     return q_atomic_decrement(&_q_value) != 0;
  457. }
  458. inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
  459. {
  460.     return q_atomic_test_and_set_int(&_q_value, expectedValue, newValue) != 0;
  461. }
  462. inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
  463. {
  464.     return q_atomic_test_and_set_acquire_int(&_q_value, expectedValue, newValue) != 0;
  465. }
  466. inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
  467. {
  468.     return q_atomic_test_and_set_release_int(&_q_value, expectedValue, newValue) != 0;
  469. }
  470. inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
  471. {
  472.     return q_atomic_set_int(&_q_value, newValue);
  473. }
  474. inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
  475. {
  476.     return q_atomic_fetch_and_store_acquire_int(&_q_value, newValue);
  477. }
  478. inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
  479. {
  480.     return q_atomic_fetch_and_store_release_int(&_q_value, newValue);
  481. }
  482. inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
  483. {
  484.     return q_atomic_fetch_and_add_int(&_q_value, valueToAdd);
  485. }
  486. inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
  487. {
  488.     return q_atomic_fetch_and_add_acquire_int(&_q_value, valueToAdd);
  489. }
  490. inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
  491. {
  492.     return q_atomic_fetch_and_add_release_int(&_q_value, valueToAdd);
  493. }
  494. template <typename T>
  495. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
  496. {
  497.     return q_atomic_test_and_set_ptr(&_q_value, expectedValue, newValue) != 0;
  498. }
  499. template <typename T>
  500. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
  501. {
  502.     return q_atomic_test_and_set_acquire_ptr(&_q_value, expectedValue, newValue) != 0;
  503. }
  504. template <typename T>
  505. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
  506. {
  507.     return q_atomic_test_and_set_release_ptr(&_q_value, expectedValue, newValue) != 0;
  508. }
  509. template <typename T>
  510. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
  511. {
  512.     return reinterpret_cast<T *>(q_atomic_set_ptr(&_q_value, newValue));
  513. }
  514. template <typename T>
  515. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
  516. {
  517.     return reinterpret_cast<T *>(q_atomic_fetch_and_store_acquire_ptr(&_q_value, newValue));
  518. }
  519. template <typename T>
  520. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
  521. {
  522.     return reinterpret_cast<T *>(q_atomic_fetch_and_store_release_ptr(&_q_value, newValue));
  523. }
  524. template <typename T>
  525. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
  526. {
  527.     return reinterpret_cast<T *>(q_atomic_fetch_and_add_ptr(&_q_value, newValue));
  528. }
  529. template <typename T>
  530. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
  531. {
  532.     return reinterpret_cast<T *>(q_atomic_fetch_and_add_acquire_ptr(&_q_value, newValue));
  533. }
  534. template <typename T>
  535. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
  536. {
  537.     return reinterpret_cast<T *>(q_atomic_fetch_and_add_release_ptr(&_q_value, newValue));
  538. }
  539. #endif // Q_CC_GNU
  540. inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
  541. {
  542.     return testAndSetAcquire(expectedValue, newValue);
  543. }
  544. inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
  545. {
  546.     return fetchAndStoreAcquire(newValue);
  547. }
  548. inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
  549. {
  550.     return fetchAndAddAcquire(valueToAdd);
  551. }
  552. template <typename T>
  553. Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
  554. {
  555.     return testAndSetAcquire(expectedValue, newValue);
  556. }
  557. template <typename T>
  558. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreOrdered(T *newValue)
  559. {
  560.     return fetchAndStoreAcquire(newValue);
  561. }
  562. template <typename T>
  563. Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
  564. {
  565.     return fetchAndAddAcquire(valueToAdd);
  566. }
  567. QT_END_NAMESPACE
  568. QT_END_HEADER
  569. #endif // QATOMIC_ALPHA_H