Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / include / linux / mutex_rt.h
1 #ifndef __LINUX_MUTEX_RT_H
2 #define __LINUX_MUTEX_RT_H
3
4 #ifndef __LINUX_MUTEX_H
5 #error "Please include mutex.h"
6 #endif
7
8 #include <linux/rtmutex.h>
9
10 /* FIXME: Just for __lockfunc */
11 #include <linux/spinlock.h>
12
13 struct mutex {
14         struct rt_mutex         lock;
15 #ifdef CONFIG_DEBUG_LOCK_ALLOC
16         struct lockdep_map      dep_map;
17 #endif
18 };
19
20 #define __MUTEX_INITIALIZER(mutexname)                                  \
21         {                                                               \
22                 .lock = __RT_MUTEX_INITIALIZER(mutexname.lock)          \
23                 __DEP_MAP_MUTEX_INITIALIZER(mutexname)                  \
24         }
25
26 #define DEFINE_MUTEX(mutexname)                                         \
27         struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
28
29 extern void __mutex_do_init(struct mutex *lock, const char *name, struct lock_class_key *key);
30 extern void __lockfunc _mutex_lock(struct mutex *lock);
31 extern int __lockfunc _mutex_lock_interruptible(struct mutex *lock);
32 extern int __lockfunc _mutex_lock_killable(struct mutex *lock);
33 extern void __lockfunc _mutex_lock_nested(struct mutex *lock, int subclass);
34 extern void __lockfunc _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest_lock);
35 extern int __lockfunc _mutex_lock_interruptible_nested(struct mutex *lock, int subclass);
36 extern int __lockfunc _mutex_lock_killable_nested(struct mutex *lock, int subclass);
37 extern int __lockfunc _mutex_trylock(struct mutex *lock);
38 extern void __lockfunc _mutex_unlock(struct mutex *lock);
39
40 #define mutex_is_locked(l)              rt_mutex_is_locked(&(l)->lock)
41 #define mutex_lock(l)                   _mutex_lock(l)
42 #define mutex_lock_interruptible(l)     _mutex_lock_interruptible(l)
43 #define mutex_lock_killable(l)          _mutex_lock_killable(l)
44 #define mutex_trylock(l)                _mutex_trylock(l)
45 #define mutex_unlock(l)                 _mutex_unlock(l)
46 #define mutex_destroy(l)                rt_mutex_destroy(&(l)->lock)
47
48 #ifdef CONFIG_DEBUG_LOCK_ALLOC
49 # define mutex_lock_nested(l, s)        _mutex_lock_nested(l, s)
50 # define mutex_lock_interruptible_nested(l, s) \
51                                         _mutex_lock_interruptible_nested(l, s)
52 # define mutex_lock_killable_nested(l, s) \
53                                         _mutex_lock_killable_nested(l, s)
54
55 # define mutex_lock_nest_lock(lock, nest_lock)                          \
56 do {                                                                    \
57         typecheck(struct lockdep_map *, &(nest_lock)->dep_map);         \
58         _mutex_lock_nest_lock(lock, &(nest_lock)->dep_map);             \
59 } while (0)
60
61 #else
62 # define mutex_lock_nested(l, s)        _mutex_lock(l)
63 # define mutex_lock_interruptible_nested(l, s) \
64                                         _mutex_lock_interruptible(l)
65 # define mutex_lock_killable_nested(l, s) \
66                                         _mutex_lock_killable(l)
67 # define mutex_lock_nest_lock(lock, nest_lock) mutex_lock(lock)
68 #endif
69
70 # define mutex_init(mutex)                              \
71 do {                                                    \
72         static struct lock_class_key __key;             \
73                                                         \
74         rt_mutex_init(&(mutex)->lock);                  \
75         __mutex_do_init((mutex), #mutex, &__key);       \
76 } while (0)
77
78 # define __mutex_init(mutex, name, key)                 \
79 do {                                                    \
80         rt_mutex_init(&(mutex)->lock);                  \
81         __mutex_do_init((mutex), name, key);            \
82 } while (0)
83
84 #endif