rwlock_types.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef __LINUX_RWLOCK_TYPES_H
  2. #define __LINUX_RWLOCK_TYPES_H
  3. /*
  4. * include/linux/rwlock_types.h - generic rwlock type definitions
  5. * and initializers
  6. *
  7. * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
  8. * Released under the General Public License (GPL).
  9. */
  10. typedef struct {
  11. arch_rwlock_t raw_lock;
  12. #ifdef CONFIG_DEBUG_SPINLOCK
  13. unsigned int magic, owner_cpu;
  14. void *owner;
  15. #endif
  16. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  17. struct lockdep_map dep_map;
  18. #endif
  19. } rwlock_t;
  20. #define RWLOCK_MAGIC 0xdeaf1eed
  21. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  22. # define RW_DEP_MAP_INIT(lockname) \
  23. .dep_map = { \
  24. .name = #lockname, \
  25. .wait_type_inner = LD_WAIT_CONFIG, \
  26. }
  27. #else
  28. # define RW_DEP_MAP_INIT(lockname)
  29. #endif
  30. #ifdef CONFIG_DEBUG_SPINLOCK
  31. #define __RW_LOCK_UNLOCKED(lockname) \
  32. (rwlock_t) { .raw_lock = __ARCH_RW_LOCK_UNLOCKED, \
  33. .magic = RWLOCK_MAGIC, \
  34. .owner = SPINLOCK_OWNER_INIT, \
  35. .owner_cpu = -1, \
  36. RW_DEP_MAP_INIT(lockname) }
  37. #else
  38. #define __RW_LOCK_UNLOCKED(lockname) \
  39. (rwlock_t) { .raw_lock = __ARCH_RW_LOCK_UNLOCKED, \
  40. RW_DEP_MAP_INIT(lockname) }
  41. #endif
  42. #define DEFINE_RWLOCK(x) rwlock_t x = __RW_LOCK_UNLOCKED(x)
  43. #endif /* __LINUX_RWLOCK_TYPES_H */