rwsem-spinlock.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* rwsem-spinlock.h: fallback C implementation
  2. *
  3. * Copyright (c) 2001 David Howells (dhowells@redhat.com).
  4. * - Derived partially from ideas by Andrea Arcangeli <andrea@suse.de>
  5. * - Derived also from comments by Linus
  6. */
  7. #ifndef _LINUX_RWSEM_SPINLOCK_H
  8. #define _LINUX_RWSEM_SPINLOCK_H
  9. #ifndef _LINUX_RWSEM_H
  10. #error "please don't include linux/rwsem-spinlock.h directly, use linux/rwsem.h instead"
  11. #endif
  12. #include <linux/spinlock.h>
  13. #include <linux/list.h>
  14. #ifdef __KERNEL__
  15. #include <linux/types.h>
  16. struct rwsem_waiter;
  17. /*
  18. * the rw-semaphore definition
  19. * - if activity is 0 then there are no active readers or writers
  20. * - if activity is +ve then that is the number of active readers
  21. * - if activity is -1 then there is one active writer
  22. * - if wait_list is not empty, then there are processes waiting for the semaphore
  23. */
  24. struct rw_semaphore {
  25. __s32 activity;
  26. spinlock_t wait_lock;
  27. struct list_head wait_list;
  28. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  29. struct lockdep_map dep_map;
  30. #endif
  31. };
  32. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  33. # define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
  34. #else
  35. # define __RWSEM_DEP_MAP_INIT(lockname)
  36. #endif
  37. #define __RWSEM_INITIALIZER(name) \
  38. { 0, __SPIN_LOCK_UNLOCKED(name.wait_lock), LIST_HEAD_INIT((name).wait_list) \
  39. __RWSEM_DEP_MAP_INIT(name) }
  40. #define DECLARE_RWSEM(name) \
  41. struct rw_semaphore name = __RWSEM_INITIALIZER(name)
  42. extern void __init_rwsem(struct rw_semaphore *sem, const char *name,
  43. struct lock_class_key *key);
  44. #define init_rwsem(sem) \
  45. do { \
  46. static struct lock_class_key __key; \
  47. \
  48. __init_rwsem((sem), #sem, &__key); \
  49. } while (0)
  50. extern void FASTCALL(__down_read(struct rw_semaphore *sem));
  51. extern int FASTCALL(__down_read_trylock(struct rw_semaphore *sem));
  52. extern void FASTCALL(__down_write(struct rw_semaphore *sem));
  53. extern void FASTCALL(__down_write_nested(struct rw_semaphore *sem, int subclass));
  54. extern int FASTCALL(__down_write_trylock(struct rw_semaphore *sem));
  55. extern void FASTCALL(__up_read(struct rw_semaphore *sem));
  56. extern void FASTCALL(__up_write(struct rw_semaphore *sem));
  57. extern void FASTCALL(__downgrade_write(struct rw_semaphore *sem));
  58. static inline int rwsem_is_locked(struct rw_semaphore *sem)
  59. {
  60. return (sem->activity != 0);
  61. }
  62. #endif /* __KERNEL__ */
  63. #endif /* _LINUX_RWSEM_SPINLOCK_H */