rwsem.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* rwsem.h: R/W semaphores, public interface
  2. *
  3. * Written by David Howells (dhowells@redhat.com).
  4. * Derived from asm-i386/semaphore.h
  5. */
  6. #ifndef _LINUX_RWSEM_H
  7. #define _LINUX_RWSEM_H
  8. #include <linux/linkage.h>
  9. #ifdef __KERNEL__
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <asm/system.h>
  13. #include <asm/atomic.h>
  14. struct rw_semaphore;
  15. #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
  16. #include <linux/rwsem-spinlock.h> /* use a generic implementation */
  17. #else
  18. #include <asm/rwsem.h> /* use an arch-specific implementation */
  19. #endif
  20. /*
  21. * lock for reading
  22. */
  23. extern void down_read(struct rw_semaphore *sem);
  24. /*
  25. * trylock for reading -- returns 1 if successful, 0 if contention
  26. */
  27. extern int down_read_trylock(struct rw_semaphore *sem);
  28. /*
  29. * lock for writing
  30. */
  31. extern void down_write(struct rw_semaphore *sem);
  32. /*
  33. * trylock for writing -- returns 1 if successful, 0 if contention
  34. */
  35. extern int down_write_trylock(struct rw_semaphore *sem);
  36. /*
  37. * release a read lock
  38. */
  39. extern void up_read(struct rw_semaphore *sem);
  40. /*
  41. * release a write lock
  42. */
  43. extern void up_write(struct rw_semaphore *sem);
  44. /*
  45. * downgrade write lock to read lock
  46. */
  47. extern void downgrade_write(struct rw_semaphore *sem);
  48. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  49. /*
  50. * nested locking. NOTE: rwsems are not allowed to recurse
  51. * (which occurs if the same task tries to acquire the same
  52. * lock instance multiple times), but multiple locks of the
  53. * same lock class might be taken, if the order of the locks
  54. * is always the same. This ordering rule can be expressed
  55. * to lockdep via the _nested() APIs, but enumerating the
  56. * subclasses that are used. (If the nesting relationship is
  57. * static then another method for expressing nested locking is
  58. * the explicit definition of lock class keys and the use of
  59. * lockdep_set_class() at lock initialization time.
  60. * See Documentation/lockdep-design.txt for more details.)
  61. */
  62. extern void down_read_nested(struct rw_semaphore *sem, int subclass);
  63. extern void down_write_nested(struct rw_semaphore *sem, int subclass);
  64. /*
  65. * Take/release a lock when not the owner will release it.
  66. *
  67. * [ This API should be avoided as much as possible - the
  68. * proper abstraction for this case is completions. ]
  69. */
  70. extern void down_read_non_owner(struct rw_semaphore *sem);
  71. extern void up_read_non_owner(struct rw_semaphore *sem);
  72. #else
  73. # define down_read_nested(sem, subclass) down_read(sem)
  74. # define down_write_nested(sem, subclass) down_write(sem)
  75. # define down_read_non_owner(sem) down_read(sem)
  76. # define up_read_non_owner(sem) up_read(sem)
  77. #endif
  78. #endif /* __KERNEL__ */
  79. #endif /* _LINUX_RWSEM_H */