rtmutex.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * RT Mutexes: blocking mutual exclusion locks with PI support
  3. *
  4. * started by Ingo Molnar and Thomas Gleixner:
  5. *
  6. * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  7. * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  8. *
  9. * This file contains the public data structure and API definitions.
  10. */
  11. #ifndef __LINUX_RT_MUTEX_H
  12. #define __LINUX_RT_MUTEX_H
  13. #include <linux/linkage.h>
  14. #include <linux/plist.h>
  15. #include <linux/spinlock_types.h>
  16. /*
  17. * The rt_mutex structure
  18. *
  19. * @wait_lock: spinlock to protect the structure
  20. * @wait_list: pilist head to enqueue waiters in priority order
  21. * @owner: the mutex owner
  22. */
  23. struct rt_mutex {
  24. spinlock_t wait_lock;
  25. struct plist_head wait_list;
  26. struct task_struct *owner;
  27. #ifdef CONFIG_DEBUG_RT_MUTEXES
  28. int save_state;
  29. struct list_head held_list_entry;
  30. unsigned long acquire_ip;
  31. const char *name, *file;
  32. int line;
  33. void *magic;
  34. #endif
  35. };
  36. struct rt_mutex_waiter;
  37. struct hrtimer_sleeper;
  38. #ifdef CONFIG_DEBUG_RT_MUTEXES
  39. extern int rt_mutex_debug_check_no_locks_freed(const void *from,
  40. unsigned long len);
  41. extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task);
  42. #else
  43. static inline int rt_mutex_debug_check_no_locks_freed(const void *from,
  44. unsigned long len)
  45. {
  46. return 0;
  47. }
  48. # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
  49. #endif
  50. #ifdef CONFIG_DEBUG_RT_MUTEXES
  51. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
  52. , .name = #mutexname, .file = __FILE__, .line = __LINE__
  53. # define rt_mutex_init(mutex) __rt_mutex_init(mutex, __FUNCTION__)
  54. extern void rt_mutex_debug_task_free(struct task_struct *tsk);
  55. #else
  56. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  57. # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL)
  58. # define rt_mutex_debug_task_free(t) do { } while (0)
  59. #endif
  60. #define __RT_MUTEX_INITIALIZER(mutexname) \
  61. { .wait_lock = SPIN_LOCK_UNLOCKED \
  62. , .wait_list = PLIST_HEAD_INIT(mutexname.wait_list, mutexname.wait_lock) \
  63. , .owner = NULL \
  64. __DEBUG_RT_MUTEX_INITIALIZER(mutexname)}
  65. #define DEFINE_RT_MUTEX(mutexname) \
  66. struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
  67. /***
  68. * rt_mutex_is_locked - is the mutex locked
  69. * @lock: the mutex to be queried
  70. *
  71. * Returns 1 if the mutex is locked, 0 if unlocked.
  72. */
  73. static inline int rt_mutex_is_locked(struct rt_mutex *lock)
  74. {
  75. return lock->owner != NULL;
  76. }
  77. extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
  78. extern void rt_mutex_destroy(struct rt_mutex *lock);
  79. extern void rt_mutex_lock(struct rt_mutex *lock);
  80. extern int rt_mutex_lock_interruptible(struct rt_mutex *lock,
  81. int detect_deadlock);
  82. extern int rt_mutex_timed_lock(struct rt_mutex *lock,
  83. struct hrtimer_sleeper *timeout,
  84. int detect_deadlock);
  85. extern int rt_mutex_trylock(struct rt_mutex *lock);
  86. extern void rt_mutex_unlock(struct rt_mutex *lock);
  87. #ifdef CONFIG_DEBUG_RT_MUTEXES
  88. # define INIT_RT_MUTEX_DEBUG(tsk) \
  89. .held_list_head = LIST_HEAD_INIT(tsk.held_list_head), \
  90. .held_list_lock = SPIN_LOCK_UNLOCKED
  91. #else
  92. # define INIT_RT_MUTEX_DEBUG(tsk)
  93. #endif
  94. #ifdef CONFIG_RT_MUTEXES
  95. # define INIT_RT_MUTEXES(tsk) \
  96. .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters, tsk.pi_lock), \
  97. INIT_RT_MUTEX_DEBUG(tsk)
  98. #else
  99. # define INIT_RT_MUTEXES(tsk)
  100. #endif
  101. #endif