qdf_atomic.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. /**
  27. * DOC: cdf_atomic.h
  28. * This file abstracts an atomic counter.
  29. */
  30. #ifndef _CDF_ATOMIC_H
  31. #define _CDF_ATOMIC_H
  32. #include <i_cdf_atomic.h>
  33. /**
  34. * cdf_atomic_t - atomic type of variable
  35. *
  36. * Use this when you want a simple resource counter etc. which is atomic
  37. * across multiple CPU's. These maybe slower than usual counters on some
  38. * platforms/OS'es, so use them with caution.
  39. */
  40. typedef __cdf_atomic_t cdf_atomic_t;
  41. /**
  42. * cdf_atomic_init() - initialize an atomic type variable
  43. * @v: A pointer to an opaque atomic variable
  44. *
  45. * Return: None
  46. */
  47. static inline void cdf_atomic_init(cdf_atomic_t *v)
  48. {
  49. __cdf_atomic_init(v);
  50. }
  51. /**
  52. * cdf_atomic_read() - read the value of an atomic variable
  53. * @v: A pointer to an opaque atomic variable
  54. *
  55. * Return: The current value of the variable
  56. */
  57. static inline int32_t cdf_atomic_read(cdf_atomic_t *v)
  58. {
  59. return __cdf_atomic_read(v);
  60. }
  61. /**
  62. * cdf_atomic_inc() - increment the value of an atomic variable
  63. * @v: A pointer to an opaque atomic variable
  64. *
  65. * Return: None
  66. */
  67. static inline void cdf_atomic_inc(cdf_atomic_t *v)
  68. {
  69. __cdf_atomic_inc(v);
  70. }
  71. /**
  72. * cdf_atomic_dec() - decrement the value of an atomic variable
  73. * @v: A pointer to an opaque atomic variable
  74. *
  75. * Return: None
  76. */
  77. static inline void cdf_atomic_dec(cdf_atomic_t *v)
  78. {
  79. __cdf_atomic_dec(v);
  80. }
  81. /**
  82. * cdf_atomic_add() - add a value to the value of an atomic variable
  83. * @v: A pointer to an opaque atomic variable
  84. * @i: The amount by which to increase the atomic counter
  85. *
  86. * Return: None
  87. */
  88. static inline void cdf_atomic_add(int i, cdf_atomic_t *v)
  89. {
  90. __cdf_atomic_add(i, v);
  91. }
  92. /**
  93. * cdf_atomic_sub() - Subtract a value from an atomic variable.
  94. * @i: the amount by which to decrease the atomic counter
  95. * @v: a pointer to an opaque atomic variable
  96. *
  97. * Return: none
  98. */
  99. static inline void cdf_atomic_sub(int i, cdf_atomic_t *v)
  100. {
  101. __cdf_atomic_sub(i, v);
  102. }
  103. /**
  104. * cdf_atomic_dec_and_test() - decrement an atomic variable and check if the
  105. * new value is zero
  106. * @v: A pointer to an opaque atomic variable
  107. *
  108. * Return:
  109. * true (non-zero) if the new value is zero,
  110. * or false (0) if the new value is non-zero
  111. */
  112. static inline int32_t cdf_atomic_dec_and_test(cdf_atomic_t *v)
  113. {
  114. return __cdf_atomic_dec_and_test(v);
  115. }
  116. /**
  117. * cdf_atomic_set() - set a value to the value of an atomic variable
  118. * @v: A pointer to an opaque atomic variable
  119. *
  120. * Return: None
  121. */
  122. static inline void cdf_atomic_set(cdf_atomic_t *v, int i)
  123. {
  124. __cdf_atomic_set(v, i);
  125. }
  126. /**
  127. * cdf_atomic_inc_return() - return the incremented value of an atomic variable
  128. * @v: A pointer to an opaque atomic variable
  129. *
  130. * Return: The current value of the variable
  131. */
  132. static inline int32_t cdf_atomic_inc_return(cdf_atomic_t *v)
  133. {
  134. return __cdf_atomic_inc_return(v);
  135. }
  136. #endif