Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / include / linux / rtmutex.h
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>
16 #include <linux/rbtree.h>
17 #include <linux/spinlock_types_raw.h>
18
19 extern int max_lock_depth; /* for sysctl */
20
21 #ifdef CONFIG_DEBUG_MUTEXES
22 #include <linux/debug_locks.h>
23 #endif
24
25 /**
26  * The rt_mutex structure
27  *
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
32  */
33 struct rt_mutex {
34         raw_spinlock_t          wait_lock;
35         struct rb_root          waiters;
36         struct rb_node          *waiters_leftmost;
37         struct task_struct      *owner;
38         int                     save_state;
39 #ifdef CONFIG_DEBUG_RT_MUTEXES
40         const char              *name, *file;
41         int                     line;
42         void                    *magic;
43 #endif
44 };
45
46 struct rt_mutex_waiter;
47 struct hrtimer_sleeper;
48
49 #ifdef CONFIG_DEBUG_RT_MUTEXES
50  extern int rt_mutex_debug_check_no_locks_freed(const void *from,
51                                                 unsigned long len);
52  extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task);
53 #else
54  static inline int rt_mutex_debug_check_no_locks_freed(const void *from,
55                                                        unsigned long len)
56  {
57         return 0;
58  }
59 # define rt_mutex_debug_check_no_locks_held(task)       do { } while (0)
60 #endif
61
62 # define rt_mutex_init(mutex)                                   \
63         do {                                                    \
64                 raw_spin_lock_init(&(mutex)->wait_lock);        \
65                 __rt_mutex_init(mutex, #mutex);                 \
66         } while (0)
67
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);
72 #else
73 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
74 # define rt_mutex_debug_task_free(t)                    do { } while (0)
75 #endif
76
77 #define __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
78          .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
79         , .waiters = RB_ROOT \
80         , .owner = NULL \
81         __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
82
83 #define __RT_MUTEX_INITIALIZER(mutexname) \
84         { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) }
85
86 #define __RT_MUTEX_INITIALIZER_SAVE_STATE(mutexname) \
87         { __RT_MUTEX_INITIALIZER_PLAIN(mutexname)    \
88         , .save_state = 1 }
89
90 #define DEFINE_RT_MUTEX(mutexname) \
91         struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
92
93 /**
94  * rt_mutex_is_locked - is the mutex locked
95  * @lock: the mutex to be queried
96  *
97  * Returns 1 if the mutex is locked, 0 if unlocked.
98  */
99 static inline int rt_mutex_is_locked(struct rt_mutex *lock)
100 {
101         return lock->owner != NULL;
102 }
103
104 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
105 extern void rt_mutex_destroy(struct rt_mutex *lock);
106
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);
112
113 extern int rt_mutex_trylock(struct rt_mutex *lock);
114
115 extern void rt_mutex_unlock(struct rt_mutex *lock);
116
117 #endif