atomic64_32.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef _ASM_X86_ATOMIC64_32_H
  2. #define _ASM_X86_ATOMIC64_32_H
  3. #include <linux/compiler.h>
  4. #include <linux/types.h>
  5. #include <asm/processor.h>
  6. //#include <asm/cmpxchg.h>
  7. /* An 64bit atomic type */
  8. typedef struct {
  9. u64 __aligned(8) counter;
  10. } atomic64_t;
  11. #define ATOMIC64_INIT(val) { (val) }
  12. extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
  13. /**
  14. * atomic64_xchg - xchg atomic64 variable
  15. * @ptr: pointer to type atomic64_t
  16. * @new_val: value to assign
  17. *
  18. * Atomically xchgs the value of @ptr to @new_val and returns
  19. * the old value.
  20. */
  21. extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
  22. /**
  23. * atomic64_set - set atomic64 variable
  24. * @ptr: pointer to type atomic64_t
  25. * @new_val: value to assign
  26. *
  27. * Atomically sets the value of @ptr to @new_val.
  28. */
  29. extern void atomic64_set(atomic64_t *ptr, u64 new_val);
  30. /**
  31. * atomic64_read - read atomic64 variable
  32. * @ptr: pointer to type atomic64_t
  33. *
  34. * Atomically reads the value of @ptr and returns it.
  35. */
  36. static inline u64 atomic64_read(atomic64_t *ptr)
  37. {
  38. u64 res;
  39. /*
  40. * Note, we inline this atomic64_t primitive because
  41. * it only clobbers EAX/EDX and leaves the others
  42. * untouched. We also (somewhat subtly) rely on the
  43. * fact that cmpxchg8b returns the current 64-bit value
  44. * of the memory location we are touching:
  45. */
  46. asm volatile(
  47. "mov %%ebx, %%eax\n\t"
  48. "mov %%ecx, %%edx\n\t"
  49. LOCK_PREFIX "cmpxchg8b %1\n"
  50. : "=&A" (res)
  51. : "m" (*ptr)
  52. );
  53. return res;
  54. }
  55. extern u64 atomic64_read(atomic64_t *ptr);
  56. /**
  57. * atomic64_add_return - add and return
  58. * @delta: integer value to add
  59. * @ptr: pointer to type atomic64_t
  60. *
  61. * Atomically adds @delta to @ptr and returns @delta + *@ptr
  62. */
  63. extern u64 atomic64_add_return(u64 delta, atomic64_t *ptr);
  64. /*
  65. * Other variants with different arithmetic operators:
  66. */
  67. extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr);
  68. extern u64 atomic64_inc_return(atomic64_t *ptr);
  69. extern u64 atomic64_dec_return(atomic64_t *ptr);
  70. /**
  71. * atomic64_add - add integer to atomic64 variable
  72. * @delta: integer value to add
  73. * @ptr: pointer to type atomic64_t
  74. *
  75. * Atomically adds @delta to @ptr.
  76. */
  77. extern void atomic64_add(u64 delta, atomic64_t *ptr);
  78. /**
  79. * atomic64_sub - subtract the atomic64 variable
  80. * @delta: integer value to subtract
  81. * @ptr: pointer to type atomic64_t
  82. *
  83. * Atomically subtracts @delta from @ptr.
  84. */
  85. extern void atomic64_sub(u64 delta, atomic64_t *ptr);
  86. /**
  87. * atomic64_sub_and_test - subtract value from variable and test result
  88. * @delta: integer value to subtract
  89. * @ptr: pointer to type atomic64_t
  90. *
  91. * Atomically subtracts @delta from @ptr and returns
  92. * true if the result is zero, or false for all
  93. * other cases.
  94. */
  95. extern int atomic64_sub_and_test(u64 delta, atomic64_t *ptr);
  96. /**
  97. * atomic64_inc - increment atomic64 variable
  98. * @ptr: pointer to type atomic64_t
  99. *
  100. * Atomically increments @ptr by 1.
  101. */
  102. extern void atomic64_inc(atomic64_t *ptr);
  103. /**
  104. * atomic64_dec - decrement atomic64 variable
  105. * @ptr: pointer to type atomic64_t
  106. *
  107. * Atomically decrements @ptr by 1.
  108. */
  109. extern void atomic64_dec(atomic64_t *ptr);
  110. /**
  111. * atomic64_dec_and_test - decrement and test
  112. * @ptr: pointer to type atomic64_t
  113. *
  114. * Atomically decrements @ptr by 1 and
  115. * returns true if the result is 0, or false for all other
  116. * cases.
  117. */
  118. extern int atomic64_dec_and_test(atomic64_t *ptr);
  119. /**
  120. * atomic64_inc_and_test - increment and test
  121. * @ptr: pointer to type atomic64_t
  122. *
  123. * Atomically increments @ptr by 1
  124. * and returns true if the result is zero, or false for all
  125. * other cases.
  126. */
  127. extern int atomic64_inc_and_test(atomic64_t *ptr);
  128. /**
  129. * atomic64_add_negative - add and test if negative
  130. * @delta: integer value to add
  131. * @ptr: pointer to type atomic64_t
  132. *
  133. * Atomically adds @delta to @ptr and returns true
  134. * if the result is negative, or false when
  135. * result is greater than or equal to zero.
  136. */
  137. extern int atomic64_add_negative(u64 delta, atomic64_t *ptr);
  138. #endif /* _ASM_X86_ATOMIC64_32_H */