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.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 * @waiters_leftmost: top waiter
27 * @owner: the mutex owner
30 raw_spinlock_t wait_lock;
31 struct rb_root waiters;
32 struct rb_node *waiters_leftmost;
33 struct task_struct *owner;
34 #ifdef CONFIG_DEBUG_RT_MUTEXES
36 const char *name, *file;
42 struct rt_mutex_waiter;
43 struct hrtimer_sleeper;
45 #ifdef CONFIG_DEBUG_RT_MUTEXES
46 extern int rt_mutex_debug_check_no_locks_freed(const void *from,
48 extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task);
50 static inline int rt_mutex_debug_check_no_locks_freed(const void *from,
55 # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
58 #ifdef CONFIG_DEBUG_RT_MUTEXES
59 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
60 , .name = #mutexname, .file = __FILE__, .line = __LINE__
61 # define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__)
62 extern void rt_mutex_debug_task_free(struct task_struct *tsk);
64 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
65 # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL)
66 # define rt_mutex_debug_task_free(t) do { } while (0)
69 #define __RT_MUTEX_INITIALIZER(mutexname) \
70 { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
71 , .waiters = RB_ROOT \
73 __DEBUG_RT_MUTEX_INITIALIZER(mutexname)}
75 #define DEFINE_RT_MUTEX(mutexname) \
76 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
79 * rt_mutex_is_locked - is the mutex locked
80 * @lock: the mutex to be queried
82 * Returns 1 if the mutex is locked, 0 if unlocked.
84 static inline int rt_mutex_is_locked(struct rt_mutex *lock)
86 return lock->owner != NULL;
89 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
90 extern void rt_mutex_destroy(struct rt_mutex *lock);
92 extern void rt_mutex_lock(struct rt_mutex *lock);
93 extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
94 extern int rt_mutex_timed_lock(struct rt_mutex *lock,
95 struct hrtimer_sleeper *timeout);
97 extern int rt_mutex_trylock(struct rt_mutex *lock);
99 extern void rt_mutex_unlock(struct rt_mutex *lock);