atomic.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #ifndef _ASM_GENERIC_ATOMIC_H
  2. #define _ASM_GENERIC_ATOMIC_H
  3. /*
  4. * Copyright (C) 2005 Silicon Graphics, Inc.
  5. * Christoph Lameter <clameter@sgi.com>
  6. *
  7. * Allows to provide arch independent atomic definitions without the need to
  8. * edit all arch specific atomic.h files.
  9. */
  10. #include <asm/types.h>
  11. #include <asm/system.h>
  12. /*
  13. * Suppport for atomic_long_t
  14. *
  15. * Casts for parameters are avoided for existing atomic functions in order to
  16. * avoid issues with cast-as-lval under gcc 4.x and other limitations that the
  17. * macros of a platform may have.
  18. */
  19. #if BITS_PER_LONG == 64
  20. typedef atomic64_t atomic_long_t;
  21. #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
  22. static inline long atomic_long_read(atomic_long_t *l)
  23. {
  24. atomic64_t *v = (atomic64_t *)l;
  25. return (long)atomic64_read(v);
  26. }
  27. static inline void atomic_long_set(atomic_long_t *l, long i)
  28. {
  29. atomic64_t *v = (atomic64_t *)l;
  30. atomic64_set(v, i);
  31. }
  32. static inline void atomic_long_inc(atomic_long_t *l)
  33. {
  34. atomic64_t *v = (atomic64_t *)l;
  35. atomic64_inc(v);
  36. }
  37. static inline void atomic_long_dec(atomic_long_t *l)
  38. {
  39. atomic64_t *v = (atomic64_t *)l;
  40. atomic64_dec(v);
  41. }
  42. static inline void atomic_long_add(long i, atomic_long_t *l)
  43. {
  44. atomic64_t *v = (atomic64_t *)l;
  45. atomic64_add(i, v);
  46. }
  47. static inline void atomic_long_sub(long i, atomic_long_t *l)
  48. {
  49. atomic64_t *v = (atomic64_t *)l;
  50. atomic64_sub(i, v);
  51. }
  52. static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
  53. {
  54. atomic64_t *v = (atomic64_t *)l;
  55. return atomic64_sub_and_test(i, v);
  56. }
  57. static inline int atomic_long_dec_and_test(atomic_long_t *l)
  58. {
  59. atomic64_t *v = (atomic64_t *)l;
  60. return atomic64_dec_and_test(v);
  61. }
  62. static inline int atomic_long_inc_and_test(atomic_long_t *l)
  63. {
  64. atomic64_t *v = (atomic64_t *)l;
  65. return atomic64_inc_and_test(v);
  66. }
  67. static inline int atomic_long_add_negative(long i, atomic_long_t *l)
  68. {
  69. atomic64_t *v = (atomic64_t *)l;
  70. return atomic64_add_negative(i, v);
  71. }
  72. static inline long atomic_long_add_return(long i, atomic_long_t *l)
  73. {
  74. atomic64_t *v = (atomic64_t *)l;
  75. return (long)atomic64_add_return(i, v);
  76. }
  77. static inline long atomic_long_sub_return(long i, atomic_long_t *l)
  78. {
  79. atomic64_t *v = (atomic64_t *)l;
  80. return (long)atomic64_sub_return(i, v);
  81. }
  82. static inline long atomic_long_inc_return(atomic_long_t *l)
  83. {
  84. atomic64_t *v = (atomic64_t *)l;
  85. return (long)atomic64_inc_return(v);
  86. }
  87. static inline long atomic_long_dec_return(atomic_long_t *l)
  88. {
  89. atomic64_t *v = (atomic64_t *)l;
  90. return (long)atomic64_dec_return(v);
  91. }
  92. #define atomic_long_add_unless(l, a, u) \
  93. atomic64_add_unless((atomic64_t *)(l), (a), (u))
  94. #define atomic_long_inc_not_zero(l) atomic64_inc_not_zero((atomic64_t *)(l))
  95. #define atomic_long_cmpxchg(l, old, new) \
  96. (atomic_cmpxchg((atomic64_t *)(l), (old), (new)))
  97. #define atomic_long_xchg(v, new) \
  98. (atomic_xchg((atomic64_t *)(l), (new)))
  99. #else /* BITS_PER_LONG == 64 */
  100. typedef atomic_t atomic_long_t;
  101. #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
  102. static inline long atomic_long_read(atomic_long_t *l)
  103. {
  104. atomic_t *v = (atomic_t *)l;
  105. return (long)atomic_read(v);
  106. }
  107. static inline void atomic_long_set(atomic_long_t *l, long i)
  108. {
  109. atomic_t *v = (atomic_t *)l;
  110. atomic_set(v, i);
  111. }
  112. static inline void atomic_long_inc(atomic_long_t *l)
  113. {
  114. atomic_t *v = (atomic_t *)l;
  115. atomic_inc(v);
  116. }
  117. static inline void atomic_long_dec(atomic_long_t *l)
  118. {
  119. atomic_t *v = (atomic_t *)l;
  120. atomic_dec(v);
  121. }
  122. static inline void atomic_long_add(long i, atomic_long_t *l)
  123. {
  124. atomic_t *v = (atomic_t *)l;
  125. atomic_add(i, v);
  126. }
  127. static inline void atomic_long_sub(long i, atomic_long_t *l)
  128. {
  129. atomic_t *v = (atomic_t *)l;
  130. atomic_sub(i, v);
  131. }
  132. static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
  133. {
  134. atomic_t *v = (atomic_t *)l;
  135. return atomic_sub_and_test(i, v);
  136. }
  137. static inline int atomic_long_dec_and_test(atomic_long_t *l)
  138. {
  139. atomic_t *v = (atomic_t *)l;
  140. return atomic_dec_and_test(v);
  141. }
  142. static inline int atomic_long_inc_and_test(atomic_long_t *l)
  143. {
  144. atomic_t *v = (atomic_t *)l;
  145. return atomic_inc_and_test(v);
  146. }
  147. static inline int atomic_long_add_negative(long i, atomic_long_t *l)
  148. {
  149. atomic_t *v = (atomic_t *)l;
  150. return atomic_add_negative(i, v);
  151. }
  152. static inline long atomic_long_add_return(long i, atomic_long_t *l)
  153. {
  154. atomic_t *v = (atomic_t *)l;
  155. return (long)atomic_add_return(i, v);
  156. }
  157. static inline long atomic_long_sub_return(long i, atomic_long_t *l)
  158. {
  159. atomic_t *v = (atomic_t *)l;
  160. return (long)atomic_sub_return(i, v);
  161. }
  162. static inline long atomic_long_inc_return(atomic_long_t *l)
  163. {
  164. atomic_t *v = (atomic_t *)l;
  165. return (long)atomic_inc_return(v);
  166. }
  167. static inline long atomic_long_dec_return(atomic_long_t *l)
  168. {
  169. atomic_t *v = (atomic_t *)l;
  170. return (long)atomic_dec_return(v);
  171. }
  172. #define atomic_long_add_unless(l, a, u) \
  173. atomic_add_unless((atomic_t *)(l), (a), (u))
  174. #define atomic_long_inc_not_zero(l) atomic_inc_not_zero((atomic_t *)(l))
  175. #define atomic_long_cmpxchg(l, old, new) \
  176. (atomic_cmpxchg((atomic_t *)(l), (old), (new)))
  177. #define atomic_long_xchg(v, new) \
  178. (atomic_xchg((atomic_t *)(l), (new)))
  179. #endif /* BITS_PER_LONG == 64 */
  180. #endif /* _ASM_GENERIC_ATOMIC_H */