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 private data structure and API definitions.
12 #ifndef __KERNEL_RTMUTEX_COMMON_H
13 #define __KERNEL_RTMUTEX_COMMON_H
15 #include <linux/rtmutex.h>
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.
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
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
32 pid_t deadlock_task_pid;
33 struct rt_mutex *deadlock_lock;
38 * Various helpers to access the waiters-plist:
40 static inline int rt_mutex_has_waiters(struct rt_mutex *lock)
42 return !plist_head_empty(&lock->wait_list);
45 static inline struct rt_mutex_waiter *
46 rt_mutex_top_waiter(struct rt_mutex *lock)
48 struct rt_mutex_waiter *w;
50 w = plist_first_entry(&lock->wait_list, struct rt_mutex_waiter,
52 BUG_ON(w->lock != lock);
57 static inline int task_has_pi_waiters(struct task_struct *p)
59 return !plist_head_empty(&p->pi_waiters);
62 static inline struct rt_mutex_waiter *
63 task_top_pi_waiter(struct task_struct *p)
65 return plist_first_entry(&p->pi_waiters, struct rt_mutex_waiter,
70 * lock->owner state tracking:
72 #define RT_MUTEX_OWNER_PENDING 1UL
73 #define RT_MUTEX_HAS_WAITERS 2UL
74 #define RT_MUTEX_OWNER_MASKALL 3UL
76 static inline struct task_struct *rt_mutex_owner(struct rt_mutex *lock)
78 return (struct task_struct *)
79 ((unsigned long)lock->owner & ~RT_MUTEX_OWNER_MASKALL);
82 static inline struct task_struct *rt_mutex_real_owner(struct rt_mutex *lock)
84 return (struct task_struct *)
85 ((unsigned long)lock->owner & ~RT_MUTEX_HAS_WAITERS);
88 static inline unsigned long rt_mutex_owner_pending(struct rt_mutex *lock)
90 return (unsigned long)lock->owner & RT_MUTEX_OWNER_PENDING;