rwsem.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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.  * Trylock by Brian Watson (Brian.J.Watson@compaq.com).
  7.  */
  8. #ifndef _LINUX_RWSEM_H
  9. #define _LINUX_RWSEM_H
  10. #include <linux/linkage.h>
  11. #define RWSEM_DEBUG 0
  12. #ifdef __KERNEL__
  13. #include <linux/config.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <asm/system.h>
  17. #include <asm/atomic.h>
  18. struct rw_semaphore;
  19. #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
  20. #include <linux/rwsem-spinlock.h> /* use a generic implementation */
  21. #else
  22. #include <asm/rwsem.h> /* use an arch-specific implementation */
  23. #endif
  24. #ifndef rwsemtrace
  25. #if RWSEM_DEBUG
  26. extern void FASTCALL(rwsemtrace(struct rw_semaphore *sem, const char *str));
  27. #else
  28. #define rwsemtrace(SEM,FMT)
  29. #endif
  30. #endif
  31. /*
  32.  * lock for reading
  33.  */
  34. static inline void down_read(struct rw_semaphore *sem)
  35. {
  36. rwsemtrace(sem,"Entering down_read");
  37. __down_read(sem);
  38. rwsemtrace(sem,"Leaving down_read");
  39. }
  40. /*
  41.  * trylock for reading -- returns 1 if successful, 0 if contention
  42.  */
  43. static inline int down_read_trylock(struct rw_semaphore *sem)
  44. {
  45. int ret;
  46. rwsemtrace(sem,"Entering down_read_trylock");
  47. ret = __down_read_trylock(sem);
  48. rwsemtrace(sem,"Leaving down_read_trylock");
  49. return ret;
  50. }
  51. /*
  52.  * lock for writing
  53.  */
  54. static inline void down_write(struct rw_semaphore *sem)
  55. {
  56. rwsemtrace(sem,"Entering down_write");
  57. __down_write(sem);
  58. rwsemtrace(sem,"Leaving down_write");
  59. }
  60. /*
  61.  * trylock for writing -- returns 1 if successful, 0 if contention
  62.  */
  63. static inline int down_write_trylock(struct rw_semaphore *sem)
  64. {
  65. int ret;
  66. rwsemtrace(sem,"Entering down_write_trylock");
  67. ret = __down_write_trylock(sem);
  68. rwsemtrace(sem,"Leaving down_write_trylock");
  69. return ret;
  70. }
  71. /*
  72.  * release a read lock
  73.  */
  74. static inline void up_read(struct rw_semaphore *sem)
  75. {
  76. rwsemtrace(sem,"Entering up_read");
  77. __up_read(sem);
  78. rwsemtrace(sem,"Leaving up_read");
  79. }
  80. /*
  81.  * release a write lock
  82.  */
  83. static inline void up_write(struct rw_semaphore *sem)
  84. {
  85. rwsemtrace(sem,"Entering up_write");
  86. __up_write(sem);
  87. rwsemtrace(sem,"Leaving up_write");
  88. }
  89. #endif /* __KERNEL__ */
  90. #endif /* _LINUX_RWSEM_H */