rwsem-spinlock.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifdef __KERNEL__
  13. /*
  14. * the rw-semaphore definition
  15. * - if activity is 0 then there are no active readers or writers
  16. * - if activity is +ve then that is the number of active readers
  17. * - if activity is -1 then there is one active writer
  18. * - if wait_list is not empty, then there are processes waiting for the semaphore
  19. */
  20. struct rw_semaphore {
  21. __s32 activity;
  22. spinlock_t wait_lock;
  23. struct list_head wait_list;
  24. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  25. struct lockdep_map dep_map;
  26. #endif
  27. };
  28. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  29. # define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
  30. #else
  31. # define __RWSEM_DEP_MAP_INIT(lockname)
  32. #endif
  33. #define __RWSEM_INITIALIZER(name) \
  34. { 0, __SPIN_LOCK_UNLOCKED(name.wait_lock), LIST_HEAD_INIT((name).wait_list) \
  35. __RWSEM_DEP_MAP_INIT(name) }
  36. #define DECLARE_RWSEM(name) \
  37. struct rw_semaphore name = __RWSEM_INITIALIZER(name)
  38. extern void __init_rwsem(struct rw_semaphore *sem, const char *name,
  39. struct lock_class_key *key);
  40. #define init_rwsem(sem) \
  41. do { \
  42. static struct lock_class_key __key; \
  43. \
  44. __init_rwsem((sem), #sem, &__key); \
  45. } while (0)
  46. extern void __down_read(struct rw_semaphore *sem);
  47. extern int __down_read_trylock(struct rw_semaphore *sem);
  48. extern void __down_write(struct rw_semaphore *sem);
  49. extern void __down_write_nested(struct rw_semaphore *sem, int subclass);
  50. extern int __down_write_trylock(struct rw_semaphore *sem);
  51. extern void __up_read(struct rw_semaphore *sem);
  52. extern void __up_write(struct rw_semaphore *sem);
  53. extern void __downgrade_write(struct rw_semaphore *sem);
  54. extern int rwsem_is_locked(struct rw_semaphore *sem);
  55. #endif /* __KERNEL__ */
  56. #endif /* _LINUX_RWSEM_SPINLOCK_H */