adf_os_lock.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted (subject to the limitations in the
  7. * disclaimer below) provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the
  15. * distribution.
  16. *
  17. * * Neither the name of Qualcomm Atheros nor the names of its
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  22. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
  23. * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  31. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  32. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  33. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. /**
  36. * @ingroup adf_os_public
  37. * @file adf_os_lock.h
  38. * This file abstracts locking operations.
  39. */
  40. #ifndef _ADF_OS_LOCK_H
  41. #define _ADF_OS_LOCK_H
  42. #include <adf_os_types.h>
  43. #include <adf_os_lock_pvt.h>
  44. /**
  45. * @brief Platform spinlock object
  46. */
  47. typedef __adf_os_spinlock_t adf_os_spinlock_t;
  48. /**
  49. * @brief Platform mutex object
  50. */
  51. typedef __adf_os_mutex_t adf_os_mutex_t;
  52. /**
  53. * @brief Initialize a mutex
  54. *
  55. * @param[in] m mutex to initialize
  56. */
  57. static inline void adf_os_init_mutex(adf_os_mutex_t *m)
  58. {
  59. __adf_os_init_mutex(m);
  60. }
  61. /**
  62. * @brief Take the mutex
  63. *
  64. * @param[in] m mutex to take
  65. */
  66. static inline int adf_os_mutex_acquire(adf_os_mutex_t *m)
  67. {
  68. return (__adf_os_mutex_acquire(m));
  69. }
  70. /**
  71. * @brief Give the mutex
  72. *
  73. * @param[in] m mutex to give
  74. */
  75. static inline void adf_os_mutex_release(adf_os_mutex_t *m)
  76. {
  77. __adf_os_mutex_release(m);
  78. }
  79. /**
  80. * @brief Initialize a spinlock
  81. *
  82. * @param[in] lock spinlock object pointer
  83. */
  84. static inline void
  85. adf_os_spinlock_init(adf_os_spinlock_t *lock)
  86. {
  87. __adf_os_spinlock_init(lock);
  88. }
  89. /**
  90. * @brief Acquire a spinlock by disabling the interrupts
  91. *
  92. * @param[in] lock spinlock object pointer
  93. * @param[out] flags flags used to hold interrupt state
  94. */
  95. static inline void
  96. adf_os_spin_lock_irq(adf_os_spinlock_t *lock, a_uint32_t *flags)
  97. {
  98. __adf_os_spin_lock_irq(lock,flags);
  99. }
  100. /**
  101. * @brief Release a spinlock & restore the irq
  102. *
  103. * @param[in] lock spinlock object pointer
  104. * @param[in] flags flags filled in by @ref adf_os_spin_lock_irq
  105. */
  106. static inline void
  107. adf_os_spin_unlock_irq(adf_os_spinlock_t *lock, a_uint32_t *flags)
  108. {
  109. __adf_os_spin_unlock_irq(lock,flags);
  110. }
  111. /**
  112. * @brief locks the spinlock mutex in soft irq context
  113. *
  114. * @param[in] lock spinlock object pointer
  115. */
  116. static inline void
  117. adf_os_spin_lock_bh(adf_os_spinlock_t *lock)
  118. {
  119. __adf_os_spin_lock_bh(lock);
  120. }
  121. /**
  122. * @brief unlocks the spinlock mutex in soft irq context
  123. *
  124. * @param[in] lock spinlock object pointer
  125. */
  126. static inline void
  127. adf_os_spin_unlock_bh(adf_os_spinlock_t *lock)
  128. {
  129. __adf_os_spin_unlock_bh(lock);
  130. }
  131. /**
  132. * @brief Execute the input function with spinlock held and interrupt disabled.
  133. *
  134. * @param[in] hdl OS handle
  135. * @param[in] lock spinlock to be held for the critical region
  136. * @param[in] func critical region function that to be executed
  137. * @param[in] context context of the critical region function
  138. *
  139. * @return Boolean status returned by the critical region function
  140. */
  141. static inline a_bool_t
  142. adf_os_spinlock_irq_exec(adf_os_handle_t hdl,
  143. adf_os_spinlock_t *lock,
  144. adf_os_irqlocked_func_t func,
  145. void *arg)
  146. {
  147. return __adf_os_spinlock_irq_exec(hdl, lock, func, arg);
  148. }
  149. #endif