2 * RT Mutexes: blocking mutual exclusion locks with PI support
4 * started by Ingo Molnar and Thomas Gleixner:
9 * This file contains the public data structure and API definitions.
12 #ifndef __LINUX_RT_MUTEX_H
13 #define __LINUX_RT_MUTEX_H
15 #include <linux/linkage.h>
16 #include <linux/rbtree.h>
17 #include <linux/spinlock_types.h>
19 extern int max_lock_depth; /* for sysctl */
22 * The rt_mutex structure
24 * @wait_lock: spinlock to protect the structure
25 * @waiters: rbtree root to enqueue waiters in priority order;
26 * caches top-waiter (leftmost node).
27 * @owner: the mutex owner
30 raw_spinlock_t wait_lock;
31 struct rb_root_cached waiters;
32 struct task_struct *owner;
33 #ifdef CONFIG_DEBUG_RT_MUTEXES
35 const char *name, *file;
39 #ifdef CONFIG_DEBUG_LOCK_ALLOC
40 struct lockdep_map dep_map;
44 struct rt_mutex_waiter;
45 struct hrtimer_sleeper;
47 #ifdef CONFIG_DEBUG_RT_MUTEXES
48 extern int rt_mutex_debug_check_no_locks_freed(const void *from,
50 extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task);
52 static inline int rt_mutex_debug_check_no_locks_freed(const void *from,
57 # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
60 #ifdef CONFIG_DEBUG_RT_MUTEXES
61 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
62 , .name = #mutexname, .file = __FILE__, .line = __LINE__
64 # define rt_mutex_init(mutex) \
66 static struct lock_class_key __key; \
67 __rt_mutex_init(mutex, __func__, &__key); \
70 extern void rt_mutex_debug_task_free(struct task_struct *tsk);
72 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
73 # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL, NULL)
74 # define rt_mutex_debug_task_free(t) do { } while (0)
77 #ifdef CONFIG_DEBUG_LOCK_ALLOC
78 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \
79 , .dep_map = { .name = #mutexname }
81 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)
84 #define __RT_MUTEX_INITIALIZER(mutexname) \
85 { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
86 , .waiters = RB_ROOT_CACHED \
88 __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
89 __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)}
91 #define DEFINE_RT_MUTEX(mutexname) \
92 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
95 * rt_mutex_is_locked - is the mutex locked
96 * @lock: the mutex to be queried
98 * Returns 1 if the mutex is locked, 0 if unlocked.
100 static inline int rt_mutex_is_locked(struct rt_mutex *lock)
102 return lock->owner != NULL;
105 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key);
106 extern void rt_mutex_destroy(struct rt_mutex *lock);
108 extern void rt_mutex_lock(struct rt_mutex *lock);
109 extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
110 extern int rt_mutex_timed_lock(struct rt_mutex *lock,
111 struct hrtimer_sleeper *timeout);
113 extern int rt_mutex_trylock(struct rt_mutex *lock);
115 extern void rt_mutex_unlock(struct rt_mutex *lock);