rtmutex.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/rbtree.h>
  15. #include <linux/spinlock_types.h>
  16. extern int max_lock_depth; /* for sysctl */
  17. /**
  18. * The rt_mutex structure
  19. *
  20. * @wait_lock: spinlock to protect the structure
  21. * @waiters: rbtree root to enqueue waiters in priority order
  22. * @waiters_leftmost: top waiter
  23. * @owner: the mutex owner
  24. */
  25. struct rt_mutex {
  26. raw_spinlock_t wait_lock;
  27. struct rb_root waiters;
  28. struct rb_node *waiters_leftmost;
  29. struct task_struct *owner;
  30. #ifdef CONFIG_DEBUG_RT_MUTEXES
  31. int save_state;
  32. const char *name, *file;
  33. int line;
  34. void *magic;
  35. #endif
  36. };
  37. struct rt_mutex_waiter;
  38. struct hrtimer_sleeper;
  39. #ifdef CONFIG_DEBUG_RT_MUTEXES
  40. extern int rt_mutex_debug_check_no_locks_freed(const void *from,
  41. unsigned long len);
  42. extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task);
  43. #else
  44. static inline int rt_mutex_debug_check_no_locks_freed(const void *from,
  45. unsigned long len)
  46. {
  47. return 0;
  48. }
  49. # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
  50. #endif
  51. #ifdef CONFIG_DEBUG_RT_MUTEXES
  52. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
  53. , .name = #mutexname, .file = __FILE__, .line = __LINE__
  54. # define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__)
  55. extern void rt_mutex_debug_task_free(struct task_struct *tsk);
  56. #else
  57. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  58. # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL)
  59. # define rt_mutex_debug_task_free(t) do { } while (0)
  60. #endif
  61. #define __RT_MUTEX_INITIALIZER(mutexname) \
  62. { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
  63. , .waiters = RB_ROOT \
  64. , .owner = NULL \
  65. __DEBUG_RT_MUTEX_INITIALIZER(mutexname)}
  66. #define DEFINE_RT_MUTEX(mutexname) \
  67. struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
  68. /**
  69. * rt_mutex_is_locked - is the mutex locked
  70. * @lock: the mutex to be queried
  71. *
  72. * Returns 1 if the mutex is locked, 0 if unlocked.
  73. */
  74. static inline int rt_mutex_is_locked(struct rt_mutex *lock)
  75. {
  76. return lock->owner != NULL;
  77. }
  78. extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
  79. extern void rt_mutex_destroy(struct rt_mutex *lock);
  80. extern void rt_mutex_lock(struct rt_mutex *lock);
  81. extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
  82. extern int rt_mutex_timed_lock(struct rt_mutex *lock,
  83. struct hrtimer_sleeper *timeout);
  84. extern int rt_mutex_trylock(struct rt_mutex *lock);
  85. extern void rt_mutex_unlock(struct rt_mutex *lock);
  86. #endif