rwlock_api_smp.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #ifndef __LINUX_RWLOCK_API_SMP_H
  2. #define __LINUX_RWLOCK_API_SMP_H
  3. #ifndef __LINUX_SPINLOCK_API_SMP_H
  4. # error "please don't include this file directly"
  5. #endif
  6. /*
  7. * include/linux/rwlock_api_smp.h
  8. *
  9. * spinlock API declarations on SMP (and debug)
  10. * (implemented in kernel/spinlock.c)
  11. *
  12. * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
  13. * Released under the General Public License (GPL).
  14. */
  15. void __lockfunc _raw_read_lock(rwlock_t *lock) __acquires(lock);
  16. void __lockfunc _raw_write_lock(rwlock_t *lock) __acquires(lock);
  17. void __lockfunc _raw_read_lock_bh(rwlock_t *lock) __acquires(lock);
  18. void __lockfunc _raw_write_lock_bh(rwlock_t *lock) __acquires(lock);
  19. void __lockfunc _raw_read_lock_irq(rwlock_t *lock) __acquires(lock);
  20. void __lockfunc _raw_write_lock_irq(rwlock_t *lock) __acquires(lock);
  21. unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock)
  22. __acquires(lock);
  23. unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock)
  24. __acquires(lock);
  25. int __lockfunc _raw_read_trylock(rwlock_t *lock);
  26. int __lockfunc _raw_write_trylock(rwlock_t *lock);
  27. void __lockfunc _raw_read_unlock(rwlock_t *lock) __releases(lock);
  28. void __lockfunc _raw_write_unlock(rwlock_t *lock) __releases(lock);
  29. void __lockfunc _raw_read_unlock_bh(rwlock_t *lock) __releases(lock);
  30. void __lockfunc _raw_write_unlock_bh(rwlock_t *lock) __releases(lock);
  31. void __lockfunc _raw_read_unlock_irq(rwlock_t *lock) __releases(lock);
  32. void __lockfunc _raw_write_unlock_irq(rwlock_t *lock) __releases(lock);
  33. void __lockfunc
  34. _raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
  35. __releases(lock);
  36. void __lockfunc
  37. _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
  38. __releases(lock);
  39. #ifdef CONFIG_INLINE_READ_LOCK
  40. #define _raw_read_lock(lock) __raw_read_lock(lock)
  41. #endif
  42. #ifdef CONFIG_INLINE_WRITE_LOCK
  43. #define _raw_write_lock(lock) __raw_write_lock(lock)
  44. #endif
  45. #ifdef CONFIG_INLINE_READ_LOCK_BH
  46. #define _raw_read_lock_bh(lock) __raw_read_lock_bh(lock)
  47. #endif
  48. #ifdef CONFIG_INLINE_WRITE_LOCK_BH
  49. #define _raw_write_lock_bh(lock) __raw_write_lock_bh(lock)
  50. #endif
  51. #ifdef CONFIG_INLINE_READ_LOCK_IRQ
  52. #define _raw_read_lock_irq(lock) __raw_read_lock_irq(lock)
  53. #endif
  54. #ifdef CONFIG_INLINE_WRITE_LOCK_IRQ
  55. #define _raw_write_lock_irq(lock) __raw_write_lock_irq(lock)
  56. #endif
  57. #ifdef CONFIG_INLINE_READ_LOCK_IRQSAVE
  58. #define _raw_read_lock_irqsave(lock) __raw_read_lock_irqsave(lock)
  59. #endif
  60. #ifdef CONFIG_INLINE_WRITE_LOCK_IRQSAVE
  61. #define _raw_write_lock_irqsave(lock) __raw_write_lock_irqsave(lock)
  62. #endif
  63. #ifdef CONFIG_INLINE_READ_TRYLOCK
  64. #define _raw_read_trylock(lock) __raw_read_trylock(lock)
  65. #endif
  66. #ifdef CONFIG_INLINE_WRITE_TRYLOCK
  67. #define _raw_write_trylock(lock) __raw_write_trylock(lock)
  68. #endif
  69. #ifdef CONFIG_INLINE_READ_UNLOCK
  70. #define _raw_read_unlock(lock) __raw_read_unlock(lock)
  71. #endif
  72. #ifdef CONFIG_INLINE_WRITE_UNLOCK
  73. #define _raw_write_unlock(lock) __raw_write_unlock(lock)
  74. #endif
  75. #ifdef CONFIG_INLINE_READ_UNLOCK_BH
  76. #define _raw_read_unlock_bh(lock) __raw_read_unlock_bh(lock)
  77. #endif
  78. #ifdef CONFIG_INLINE_WRITE_UNLOCK_BH
  79. #define _raw_write_unlock_bh(lock) __raw_write_unlock_bh(lock)
  80. #endif
  81. #ifdef CONFIG_INLINE_READ_UNLOCK_IRQ
  82. #define _raw_read_unlock_irq(lock) __raw_read_unlock_irq(lock)
  83. #endif
  84. #ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQ
  85. #define _raw_write_unlock_irq(lock) __raw_write_unlock_irq(lock)
  86. #endif
  87. #ifdef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE
  88. #define _raw_read_unlock_irqrestore(lock, flags) \
  89. __raw_read_unlock_irqrestore(lock, flags)
  90. #endif
  91. #ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
  92. #define _raw_write_unlock_irqrestore(lock, flags) \
  93. __raw_write_unlock_irqrestore(lock, flags)
  94. #endif
  95. static inline int __raw_read_trylock(rwlock_t *lock)
  96. {
  97. preempt_disable();
  98. if (do_raw_read_trylock(lock)) {
  99. rwlock_acquire_read(&lock->dep_map, 0, 1, _RET_IP_);
  100. return 1;
  101. }
  102. preempt_enable();
  103. return 0;
  104. }
  105. static inline int __raw_write_trylock(rwlock_t *lock)
  106. {
  107. preempt_disable();
  108. if (do_raw_write_trylock(lock)) {
  109. rwlock_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  110. return 1;
  111. }
  112. preempt_enable();
  113. return 0;
  114. }
  115. /*
  116. * If lockdep is enabled then we use the non-preemption spin-ops
  117. * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are
  118. * not re-enabled during lock-acquire (which the preempt-spin-ops do):
  119. */
  120. #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
  121. static inline void __raw_read_lock(rwlock_t *lock)
  122. {
  123. preempt_disable();
  124. rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
  125. LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
  126. }
  127. static inline unsigned long __raw_read_lock_irqsave(rwlock_t *lock)
  128. {
  129. unsigned long flags;
  130. local_irq_save(flags);
  131. preempt_disable();
  132. rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
  133. LOCK_CONTENDED_FLAGS(lock, do_raw_read_trylock, do_raw_read_lock,
  134. do_raw_read_lock_flags, &flags);
  135. return flags;
  136. }
  137. static inline void __raw_read_lock_irq(rwlock_t *lock)
  138. {
  139. local_irq_disable();
  140. preempt_disable();
  141. rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
  142. LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
  143. }
  144. static inline void __raw_read_lock_bh(rwlock_t *lock)
  145. {
  146. __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
  147. rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
  148. LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
  149. }
  150. static inline unsigned long __raw_write_lock_irqsave(rwlock_t *lock)
  151. {
  152. unsigned long flags;
  153. local_irq_save(flags);
  154. preempt_disable();
  155. rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  156. LOCK_CONTENDED_FLAGS(lock, do_raw_write_trylock, do_raw_write_lock,
  157. do_raw_write_lock_flags, &flags);
  158. return flags;
  159. }
  160. static inline void __raw_write_lock_irq(rwlock_t *lock)
  161. {
  162. local_irq_disable();
  163. preempt_disable();
  164. rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  165. LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
  166. }
  167. static inline void __raw_write_lock_bh(rwlock_t *lock)
  168. {
  169. __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
  170. rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  171. LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
  172. }
  173. static inline void __raw_write_lock(rwlock_t *lock)
  174. {
  175. preempt_disable();
  176. rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  177. LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
  178. }
  179. #endif /* CONFIG_PREEMPT */
  180. static inline void __raw_write_unlock(rwlock_t *lock)
  181. {
  182. rwlock_release(&lock->dep_map, 1, _RET_IP_);
  183. do_raw_write_unlock(lock);
  184. preempt_enable();
  185. }
  186. static inline void __raw_read_unlock(rwlock_t *lock)
  187. {
  188. rwlock_release(&lock->dep_map, 1, _RET_IP_);
  189. do_raw_read_unlock(lock);
  190. preempt_enable();
  191. }
  192. static inline void
  193. __raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
  194. {
  195. rwlock_release(&lock->dep_map, 1, _RET_IP_);
  196. do_raw_read_unlock(lock);
  197. local_irq_restore(flags);
  198. preempt_enable();
  199. }
  200. static inline void __raw_read_unlock_irq(rwlock_t *lock)
  201. {
  202. rwlock_release(&lock->dep_map, 1, _RET_IP_);
  203. do_raw_read_unlock(lock);
  204. local_irq_enable();
  205. preempt_enable();
  206. }
  207. static inline void __raw_read_unlock_bh(rwlock_t *lock)
  208. {
  209. rwlock_release(&lock->dep_map, 1, _RET_IP_);
  210. do_raw_read_unlock(lock);
  211. __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
  212. }
  213. static inline void __raw_write_unlock_irqrestore(rwlock_t *lock,
  214. unsigned long flags)
  215. {
  216. rwlock_release(&lock->dep_map, 1, _RET_IP_);
  217. do_raw_write_unlock(lock);
  218. local_irq_restore(flags);
  219. preempt_enable();
  220. }
  221. static inline void __raw_write_unlock_irq(rwlock_t *lock)
  222. {
  223. rwlock_release(&lock->dep_map, 1, _RET_IP_);
  224. do_raw_write_unlock(lock);
  225. local_irq_enable();
  226. preempt_enable();
  227. }
  228. static inline void __raw_write_unlock_bh(rwlock_t *lock)
  229. {
  230. rwlock_release(&lock->dep_map, 1, _RET_IP_);
  231. do_raw_write_unlock(lock);
  232. __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
  233. }
  234. #endif /* __LINUX_RWLOCK_API_SMP_H */