atomic-long.h 5.2 KB

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