rtmutex.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. const char *name, *file;
  30. int line;
  31. void *magic;
  32. #endif
  33. };
  34. struct rt_mutex_waiter;
  35. struct hrtimer_sleeper;
  36. #ifdef CONFIG_DEBUG_RT_MUTEXES
  37. extern int rt_mutex_debug_check_no_locks_freed(const void *from,
  38. unsigned long len);
  39. extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task);
  40. #else
  41. static inline int rt_mutex_debug_check_no_locks_freed(const void *from,
  42. unsigned long len)
  43. {
  44. return 0;
  45. }
  46. # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
  47. #endif
  48. #ifdef CONFIG_DEBUG_RT_MUTEXES
  49. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
  50. , .name = #mutexname, .file = __FILE__, .line = __LINE__
  51. # define rt_mutex_init(mutex) __rt_mutex_init(mutex, __FUNCTION__)
  52. extern void rt_mutex_debug_task_free(struct task_struct *tsk);
  53. #else
  54. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  55. # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL)
  56. # define rt_mutex_debug_task_free(t) do { } while (0)
  57. #endif
  58. #define __RT_MUTEX_INITIALIZER(mutexname) \
  59. { .wait_lock = __SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
  60. , .wait_list = PLIST_HEAD_INIT(mutexname.wait_list, mutexname.wait_lock) \
  61. , .owner = NULL \
  62. __DEBUG_RT_MUTEX_INITIALIZER(mutexname)}
  63. #define DEFINE_RT_MUTEX(mutexname) \
  64. struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
  65. /**
  66. * rt_mutex_is_locked - is the mutex locked
  67. * @lock: the mutex to be queried
  68. *
  69. * Returns 1 if the mutex is locked, 0 if unlocked.
  70. */
  71. static inline int rt_mutex_is_locked(struct rt_mutex *lock)
  72. {
  73. return lock->owner != NULL;
  74. }
  75. extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
  76. extern void rt_mutex_destroy(struct rt_mutex *lock);
  77. extern void rt_mutex_lock(struct rt_mutex *lock);
  78. extern int rt_mutex_lock_interruptible(struct rt_mutex *lock,
  79. int detect_deadlock);
  80. extern int rt_mutex_timed_lock(struct rt_mutex *lock,
  81. struct hrtimer_sleeper *timeout,
  82. int detect_deadlock);
  83. extern int rt_mutex_trylock(struct rt_mutex *lock);
  84. extern void rt_mutex_unlock(struct rt_mutex *lock);
  85. #ifdef CONFIG_RT_MUTEXES
  86. # define INIT_RT_MUTEXES(tsk) \
  87. .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters, tsk.pi_lock), \
  88. INIT_RT_MUTEX_DEBUG(tsk)
  89. #else
  90. # define INIT_RT_MUTEXES(tsk)
  91. #endif
  92. #endif