]>
Commit | Line | Data |
---|---|---|
23f78d4a IM |
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 | ||
12 | #ifndef __LINUX_RT_MUTEX_H | |
13 | #define __LINUX_RT_MUTEX_H | |
14 | ||
15 | #include <linux/linkage.h> | |
fb00aca4 | 16 | #include <linux/rbtree.h> |
23f78d4a IM |
17 | #include <linux/spinlock_types.h> |
18 | ||
4f0e056f DY |
19 | extern int max_lock_depth; /* for sysctl */ |
20 | ||
45f8bde0 | 21 | /** |
23f78d4a IM |
22 | * The rt_mutex structure |
23 | * | |
24 | * @wait_lock: spinlock to protect the structure | |
fb00aca4 PZ |
25 | * @waiters: rbtree root to enqueue waiters in priority order |
26 | * @waiters_leftmost: top waiter | |
23f78d4a IM |
27 | * @owner: the mutex owner |
28 | */ | |
29 | struct rt_mutex { | |
d209d74d | 30 | raw_spinlock_t wait_lock; |
fb00aca4 PZ |
31 | struct rb_root waiters; |
32 | struct rb_node *waiters_leftmost; | |
23f78d4a IM |
33 | struct task_struct *owner; |
34 | #ifdef CONFIG_DEBUG_RT_MUTEXES | |
35 | int save_state; | |
23f78d4a IM |
36 | const char *name, *file; |
37 | int line; | |
38 | void *magic; | |
39 | #endif | |
f5694788 PZ |
40 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
41 | struct lockdep_map dep_map; | |
42 | #endif | |
23f78d4a IM |
43 | }; |
44 | ||
45 | struct rt_mutex_waiter; | |
46 | struct hrtimer_sleeper; | |
47 | ||
e7eebaf6 IM |
48 | #ifdef CONFIG_DEBUG_RT_MUTEXES |
49 | extern int rt_mutex_debug_check_no_locks_freed(const void *from, | |
50 | unsigned long len); | |
51 | extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task); | |
52 | #else | |
53 | static inline int rt_mutex_debug_check_no_locks_freed(const void *from, | |
54 | unsigned long len) | |
55 | { | |
56 | return 0; | |
57 | } | |
58 | # define rt_mutex_debug_check_no_locks_held(task) do { } while (0) | |
59 | #endif | |
60 | ||
23f78d4a IM |
61 | #ifdef CONFIG_DEBUG_RT_MUTEXES |
62 | # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \ | |
63 | , .name = #mutexname, .file = __FILE__, .line = __LINE__ | |
f5694788 PZ |
64 | |
65 | # define rt_mutex_init(mutex) \ | |
66 | do { \ | |
67 | static struct lock_class_key __key; \ | |
68 | __rt_mutex_init(mutex, __func__, &__key); \ | |
69 | } while (0) | |
70 | ||
23f78d4a IM |
71 | extern void rt_mutex_debug_task_free(struct task_struct *tsk); |
72 | #else | |
73 | # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) | |
f5694788 | 74 | # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL, NULL) |
e7eebaf6 | 75 | # define rt_mutex_debug_task_free(t) do { } while (0) |
23f78d4a IM |
76 | #endif |
77 | ||
f5694788 PZ |
78 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
79 | #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ | |
80 | , .dep_map = { .name = #mutexname } | |
81 | #else | |
82 | #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) | |
83 | #endif | |
84 | ||
23f78d4a | 85 | #define __RT_MUTEX_INITIALIZER(mutexname) \ |
d209d74d | 86 | { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ |
fb00aca4 | 87 | , .waiters = RB_ROOT \ |
23f78d4a | 88 | , .owner = NULL \ |
f5694788 PZ |
89 | __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \ |
90 | __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)} | |
23f78d4a IM |
91 | |
92 | #define DEFINE_RT_MUTEX(mutexname) \ | |
93 | struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) | |
94 | ||
45f8bde0 | 95 | /** |
23f78d4a IM |
96 | * rt_mutex_is_locked - is the mutex locked |
97 | * @lock: the mutex to be queried | |
98 | * | |
99 | * Returns 1 if the mutex is locked, 0 if unlocked. | |
100 | */ | |
101 | static inline int rt_mutex_is_locked(struct rt_mutex *lock) | |
102 | { | |
103 | return lock->owner != NULL; | |
104 | } | |
105 | ||
f5694788 | 106 | extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key); |
23f78d4a IM |
107 | extern void rt_mutex_destroy(struct rt_mutex *lock); |
108 | ||
109 | extern void rt_mutex_lock(struct rt_mutex *lock); | |
c051b21f | 110 | extern int rt_mutex_lock_interruptible(struct rt_mutex *lock); |
23f78d4a | 111 | extern int rt_mutex_timed_lock(struct rt_mutex *lock, |
c051b21f | 112 | struct hrtimer_sleeper *timeout); |
23f78d4a IM |
113 | |
114 | extern int rt_mutex_trylock(struct rt_mutex *lock); | |
115 | ||
116 | extern void rt_mutex_unlock(struct rt_mutex *lock); | |
117 | ||
23f78d4a | 118 | #endif |