atomic-long.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. #ifndef __UBOOT__
  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. static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
  93. {
  94. atomic64_t *v = (atomic64_t *)l;
  95. return (long)atomic64_add_unless(v, a, u);
  96. }
  97. #define atomic_long_inc_not_zero(l) atomic64_inc_not_zero((atomic64_t *)(l))
  98. #define atomic_long_cmpxchg(l, old, new) \
  99. (atomic64_cmpxchg((atomic64_t *)(l), (old), (new)))
  100. #define atomic_long_xchg(v, new) \
  101. (atomic64_xchg((atomic64_t *)(v), (new)))
  102. #endif /* __UBOOT__ */
  103. #else /* BITS_PER_LONG == 64 */
  104. typedef atomic_t atomic_long_t;
  105. #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
  106. static inline long atomic_long_read(atomic_long_t *l)
  107. {
  108. atomic_t *v = (atomic_t *)l;
  109. return (long)atomic_read(v);
  110. }
  111. static inline void atomic_long_set(atomic_long_t *l, long i)
  112. {
  113. atomic_t *v = (atomic_t *)l;
  114. atomic_set(v, i);
  115. }
  116. static inline void atomic_long_inc(atomic_long_t *l)
  117. {
  118. atomic_t *v = (atomic_t *)l;
  119. atomic_inc(v);
  120. }
  121. static inline void atomic_long_dec(atomic_long_t *l)
  122. {
  123. atomic_t *v = (atomic_t *)l;
  124. atomic_dec(v);
  125. }
  126. static inline void atomic_long_add(long i, atomic_long_t *l)
  127. {
  128. atomic_t *v = (atomic_t *)l;
  129. atomic_add(i, v);
  130. }
  131. static inline void atomic_long_sub(long i, atomic_long_t *l)
  132. {
  133. atomic_t *v = (atomic_t *)l;
  134. atomic_sub(i, v);
  135. }
  136. #ifndef __UBOOT__
  137. static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
  138. {
  139. atomic_t *v = (atomic_t *)l;
  140. return atomic_sub_and_test(i, v);
  141. }
  142. static inline int atomic_long_dec_and_test(atomic_long_t *l)
  143. {
  144. atomic_t *v = (atomic_t *)l;
  145. return atomic_dec_and_test(v);
  146. }
  147. static inline int atomic_long_inc_and_test(atomic_long_t *l)
  148. {
  149. atomic_t *v = (atomic_t *)l;
  150. return atomic_inc_and_test(v);
  151. }
  152. static inline int atomic_long_add_negative(long i, atomic_long_t *l)
  153. {
  154. atomic_t *v = (atomic_t *)l;
  155. return atomic_add_negative(i, v);
  156. }
  157. static inline long atomic_long_add_return(long i, atomic_long_t *l)
  158. {
  159. atomic_t *v = (atomic_t *)l;
  160. return (long)atomic_add_return(i, v);
  161. }
  162. static inline long atomic_long_sub_return(long i, atomic_long_t *l)
  163. {
  164. atomic_t *v = (atomic_t *)l;
  165. return (long)atomic_sub_return(i, v);
  166. }
  167. static inline long atomic_long_inc_return(atomic_long_t *l)
  168. {
  169. atomic_t *v = (atomic_t *)l;
  170. return (long)atomic_inc_return(v);
  171. }
  172. static inline long atomic_long_dec_return(atomic_long_t *l)
  173. {
  174. atomic_t *v = (atomic_t *)l;
  175. return (long)atomic_dec_return(v);
  176. }
  177. static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
  178. {
  179. atomic_t *v = (atomic_t *)l;
  180. return (long)atomic_add_unless(v, a, u);
  181. }
  182. #define atomic_long_inc_not_zero(l) atomic_inc_not_zero((atomic_t *)(l))
  183. #define atomic_long_cmpxchg(l, old, new) \
  184. (atomic_cmpxchg((atomic_t *)(l), (old), (new)))
  185. #define atomic_long_xchg(v, new) \
  186. (atomic_xchg((atomic_t *)(v), (new)))
  187. #endif /* __UBOOT__ */
  188. #endif /* BITS_PER_LONG == 64 */
  189. #endif /* _ASM_GENERIC_ATOMIC_LONG_H */