2 * RT Mutexes: blocking mutual exclusion locks with PI support
4 * started by Ingo Molnar and Thomas Gleixner:
6 * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
7 * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
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_raw.h>
19 extern int max_lock_depth; /* for sysctl */
21 #ifdef CONFIG_DEBUG_MUTEXES
22 #include <linux/debug_locks.h>
26 * The rt_mutex structure
28 * @wait_lock: spinlock to protect the structure
29 * @waiters: rbtree root to enqueue waiters in priority order
30 * @waiters_leftmost: top waiter
31 * @owner: the mutex owner
34 raw_spinlock_t wait_lock;
35 struct rb_root waiters;
36 struct rb_node *waiters_leftmost;
37 struct task_struct *owner;
39 #ifdef CONFIG_DEBUG_RT_MUTEXES
40 const char *name, *file;
46 struct rt_mutex_waiter;
47 struct hrtimer_sleeper;
49 #ifdef CONFIG_DEBUG_RT_MUTEXES
50 extern int rt_mutex_debug_check_no_locks_freed(const void *from,
52 extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task);
54 static inline int rt_mutex_debug_check_no_locks_freed(const void *from,
59 # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
62 # define rt_mutex_init(mutex) \
64 raw_spin_lock_init(&(mutex)->wait_lock); \
65 __rt_mutex_init(mutex, #mutex); \
68 #ifdef CONFIG_DEBUG_RT_MUTEXES
69 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
70 , .name = #mutexname, .file = __FILE__, .line = __LINE__
71 extern void rt_mutex_debug_task_free(struct task_struct *tsk);
73 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
74 # define rt_mutex_debug_task_free(t) do { } while (0)
77 #define __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
78 .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
79 , .waiters = RB_ROOT \
81 __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
83 #define __RT_MUTEX_INITIALIZER(mutexname) \
84 { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) }
86 #define __RT_MUTEX_INITIALIZER_SAVE_STATE(mutexname) \
87 { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
90 #define DEFINE_RT_MUTEX(mutexname) \
91 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
94 * rt_mutex_is_locked - is the mutex locked
95 * @lock: the mutex to be queried
97 * Returns 1 if the mutex is locked, 0 if unlocked.
99 static inline int rt_mutex_is_locked(struct rt_mutex *lock)
101 return lock->owner != NULL;
104 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
105 extern void rt_mutex_destroy(struct rt_mutex *lock);
107 extern void rt_mutex_lock(struct rt_mutex *lock);
108 extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
109 extern int rt_mutex_lock_killable(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);