_sparc_atomic.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Currently, SUN CC requires object file
  2. #if defined (__GNUC__)
  3. /*
  4. ** int _STLP_atomic_exchange (__stl_atomic_t *pvalue, __stl_atomic_t value)
  5. */
  6. # if defined(__sparc_v9__) || defined (__sparcv9)
  7. # ifdef __arch64__
  8. # define _STLP_EXCH_ASM asm volatile ("casx [%3], %4, %0 ; membar #LoadLoad | #LoadStore " : \
  9. "=r" (_L_value2), "=m" (*_L_pvalue1) : \
  10. "m" (*_L_pvalue1), "r" (_L_pvalue1), "r" (_L_value1), "0" (_L_value2) )
  11. # else /* __arch64__ */
  12. # define _STLP_EXCH_ASM asm volatile ("cas [%3], %4, %0" : \
  13. "=r" (_L_value2), "=m" (*_L_pvalue1) : \
  14. "m" (*_L_pvalue1), "r" (_L_pvalue1), "r" (_L_value1), "0" (_L_value2) )
  15. # endif
  16. # else /* __sparc_v9__ */
  17. # define _STLP_EXCH_ASM asm volatile ("swap [%3], %0 " : \
  18. "=r" (_L_value2), "=m" (*_L_pvalue1) : \
  19. "m" (*_L_pvalue1), "r" (_L_pvalue1), "0" (_L_value2) )
  20. # endif
  21. # define _STLP_ATOMIC_EXCHANGE(__pvalue1, __value2) \
  22. ({ register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \
  23. register __stl_atomic_t _L_value1, _L_value2 = __value2 ; \
  24. do { _L_value1 = *_L_pvalue1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; \
  25. _L_value1; })
  26. # define _STLP_ATOMIC_INCREMENT(__pvalue1) \
  27. ({ register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \
  28. register __stl_atomic_t _L_value1, _L_value2; \
  29. do { _L_value1 = *_L_pvalue1; _L_value2 = _L_value1+1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; \
  30. (_L_value2 + 1); })
  31. # define _STLP_ATOMIC_DECREMENT(__pvalue1) \
  32. ({ register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \
  33. register __stl_atomic_t _L_value1, _L_value2; \
  34. do { _L_value1 = *_L_pvalue1; _L_value2 = _L_value1-1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; \
  35. (_L_value2 - 1); })
  36. # elif ! defined (_STLP_NO_EXTERN_INLINE)
  37. extern "C" __stl_atomic_t _STLP_atomic_exchange(__stl_atomic_t * __x, __stl_atomic_t __v);
  38. extern "C" void _STLP_atomic_decrement(__stl_atomic_t* i);
  39. extern "C" void _STLP_atomic_increment(__stl_atomic_t* i);
  40. # define _STLP_ATOMIC_INCREMENT(__x) _STLP_atomic_increment((__stl_atomic_t*)__x)
  41. # define _STLP_ATOMIC_DECREMENT(__x) _STLP_atomic_decrement((__stl_atomic_t*)__x)
  42. # define _STLP_ATOMIC_EXCHANGE(__x, __y) _STLP_atomic_exchange((__stl_atomic_t*)__x, (__stl_atomic_t)__y)
  43. #endif