spinlock_types.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef __LINUX_SPINLOCK_TYPES_H
  2. #define __LINUX_SPINLOCK_TYPES_H
  3. /*
  4. * include/linux/spinlock_types.h - generic spinlock 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. #if defined(CONFIG_SMP)
  11. # include <asm/spinlock_types.h>
  12. #else
  13. # include <linux/spinlock_types_up.h>
  14. #endif
  15. #include <linux/lockdep.h>
  16. typedef struct raw_spinlock {
  17. arch_spinlock_t raw_lock;
  18. #ifdef CONFIG_GENERIC_LOCKBREAK
  19. unsigned int break_lock;
  20. #endif
  21. #ifdef CONFIG_DEBUG_SPINLOCK
  22. unsigned int magic, owner_cpu;
  23. void *owner;
  24. #endif
  25. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  26. struct lockdep_map dep_map;
  27. #endif
  28. } raw_spinlock_t;
  29. #define SPINLOCK_MAGIC 0xdead4ead
  30. #define SPINLOCK_OWNER_INIT ((void *)-1L)
  31. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  32. # define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  33. #else
  34. # define SPIN_DEP_MAP_INIT(lockname)
  35. #endif
  36. #ifdef CONFIG_DEBUG_SPINLOCK
  37. # define SPIN_DEBUG_INIT(lockname) \
  38. .magic = SPINLOCK_MAGIC, \
  39. .owner_cpu = -1, \
  40. .owner = SPINLOCK_OWNER_INIT,
  41. #else
  42. # define SPIN_DEBUG_INIT(lockname)
  43. #endif
  44. #define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
  45. { \
  46. .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
  47. SPIN_DEBUG_INIT(lockname) \
  48. SPIN_DEP_MAP_INIT(lockname) }
  49. #define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
  50. (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
  51. #define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
  52. typedef struct spinlock {
  53. union {
  54. struct raw_spinlock rlock;
  55. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  56. # define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
  57. struct {
  58. u8 __padding[LOCK_PADSIZE];
  59. struct lockdep_map dep_map;
  60. };
  61. #endif
  62. };
  63. } spinlock_t;
  64. #define __SPIN_LOCK_INITIALIZER(lockname) \
  65. { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
  66. #define __SPIN_LOCK_UNLOCKED(lockname) \
  67. (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
  68. #define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
  69. #include <linux/rwlock_types.h>
  70. #endif /* __LINUX_SPINLOCK_TYPES_H */