diff options
Diffstat (limited to 'kernel/rtmutex_common.h')
-rw-r--r-- | kernel/rtmutex_common.h | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/kernel/rtmutex_common.h b/kernel/rtmutex_common.h new file mode 100644 index 000000000000..50eed60eb085 --- /dev/null +++ b/kernel/rtmutex_common.h | |||
@@ -0,0 +1,93 @@ | |||
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 private data structure and API definitions. | ||
10 | */ | ||
11 | |||
12 | #ifndef __KERNEL_RTMUTEX_COMMON_H | ||
13 | #define __KERNEL_RTMUTEX_COMMON_H | ||
14 | |||
15 | #include <linux/rtmutex.h> | ||
16 | |||
17 | /* | ||
18 | * This is the control structure for tasks blocked on a rt_mutex, | ||
19 | * which is allocated on the kernel stack on of the blocked task. | ||
20 | * | ||
21 | * @list_entry: pi node to enqueue into the mutex waiters list | ||
22 | * @pi_list_entry: pi node to enqueue into the mutex owner waiters list | ||
23 | * @task: task reference to the blocked task | ||
24 | */ | ||
25 | struct rt_mutex_waiter { | ||
26 | struct plist_node list_entry; | ||
27 | struct plist_node pi_list_entry; | ||
28 | struct task_struct *task; | ||
29 | struct rt_mutex *lock; | ||
30 | #ifdef CONFIG_DEBUG_RT_MUTEXES | ||
31 | unsigned long ip; | ||
32 | pid_t deadlock_task_pid; | ||
33 | struct rt_mutex *deadlock_lock; | ||
34 | #endif | ||
35 | }; | ||
36 | |||
37 | /* | ||
38 | * Various helpers to access the waiters-plist: | ||
39 | */ | ||
40 | static inline int rt_mutex_has_waiters(struct rt_mutex *lock) | ||
41 | { | ||
42 | return !plist_head_empty(&lock->wait_list); | ||
43 | } | ||
44 | |||
45 | static inline struct rt_mutex_waiter * | ||
46 | rt_mutex_top_waiter(struct rt_mutex *lock) | ||
47 | { | ||
48 | struct rt_mutex_waiter *w; | ||
49 | |||
50 | w = plist_first_entry(&lock->wait_list, struct rt_mutex_waiter, | ||
51 | list_entry); | ||
52 | BUG_ON(w->lock != lock); | ||
53 | |||
54 | return w; | ||
55 | } | ||
56 | |||
57 | static inline int task_has_pi_waiters(struct task_struct *p) | ||
58 | { | ||
59 | return !plist_head_empty(&p->pi_waiters); | ||
60 | } | ||
61 | |||
62 | static inline struct rt_mutex_waiter * | ||
63 | task_top_pi_waiter(struct task_struct *p) | ||
64 | { | ||
65 | return plist_first_entry(&p->pi_waiters, struct rt_mutex_waiter, | ||
66 | pi_list_entry); | ||
67 | } | ||
68 | |||
69 | /* | ||
70 | * lock->owner state tracking: | ||
71 | */ | ||
72 | #define RT_MUTEX_OWNER_PENDING 1UL | ||
73 | #define RT_MUTEX_HAS_WAITERS 2UL | ||
74 | #define RT_MUTEX_OWNER_MASKALL 3UL | ||
75 | |||
76 | static inline struct task_struct *rt_mutex_owner(struct rt_mutex *lock) | ||
77 | { | ||
78 | return (struct task_struct *) | ||
79 | ((unsigned long)lock->owner & ~RT_MUTEX_OWNER_MASKALL); | ||
80 | } | ||
81 | |||
82 | static inline struct task_struct *rt_mutex_real_owner(struct rt_mutex *lock) | ||
83 | { | ||
84 | return (struct task_struct *) | ||
85 | ((unsigned long)lock->owner & ~RT_MUTEX_HAS_WAITERS); | ||
86 | } | ||
87 | |||
88 | static inline unsigned long rt_mutex_owner_pending(struct rt_mutex *lock) | ||
89 | { | ||
90 | return (unsigned long)lock->owner & RT_MUTEX_OWNER_PENDING; | ||
91 | } | ||
92 | |||
93 | #endif | ||