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