0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef __LINUX_RT_MUTEX_H
0014 #define __LINUX_RT_MUTEX_H
0015
0016 #include <linux/compiler.h>
0017 #include <linux/linkage.h>
0018 #include <linux/rbtree_types.h>
0019 #include <linux/spinlock_types_raw.h>
0020
0021 extern int max_lock_depth;
0022
0023 struct rt_mutex_base {
0024 raw_spinlock_t wait_lock;
0025 struct rb_root_cached waiters;
0026 struct task_struct *owner;
0027 };
0028
0029 #define __RT_MUTEX_BASE_INITIALIZER(rtbasename) \
0030 { \
0031 .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(rtbasename.wait_lock), \
0032 .waiters = RB_ROOT_CACHED, \
0033 .owner = NULL \
0034 }
0035
0036
0037
0038
0039
0040
0041
0042 static inline bool rt_mutex_base_is_locked(struct rt_mutex_base *lock)
0043 {
0044 return READ_ONCE(lock->owner) != NULL;
0045 }
0046
0047 extern void rt_mutex_base_init(struct rt_mutex_base *rtb);
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 struct rt_mutex {
0058 struct rt_mutex_base rtmutex;
0059 #ifdef CONFIG_DEBUG_LOCK_ALLOC
0060 struct lockdep_map dep_map;
0061 #endif
0062 };
0063
0064 struct rt_mutex_waiter;
0065 struct hrtimer_sleeper;
0066
0067 #ifdef CONFIG_DEBUG_RT_MUTEXES
0068 extern void rt_mutex_debug_task_free(struct task_struct *tsk);
0069 #else
0070 static inline void rt_mutex_debug_task_free(struct task_struct *tsk) { }
0071 #endif
0072
0073 #define rt_mutex_init(mutex) \
0074 do { \
0075 static struct lock_class_key __key; \
0076 __rt_mutex_init(mutex, __func__, &__key); \
0077 } while (0)
0078
0079 #ifdef CONFIG_DEBUG_LOCK_ALLOC
0080 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \
0081 .dep_map = { \
0082 .name = #mutexname, \
0083 .wait_type_inner = LD_WAIT_SLEEP, \
0084 }
0085 #else
0086 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)
0087 #endif
0088
0089 #define __RT_MUTEX_INITIALIZER(mutexname) \
0090 { \
0091 .rtmutex = __RT_MUTEX_BASE_INITIALIZER(mutexname.rtmutex), \
0092 __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \
0093 }
0094
0095 #define DEFINE_RT_MUTEX(mutexname) \
0096 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
0097
0098 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key);
0099
0100 #ifdef CONFIG_DEBUG_LOCK_ALLOC
0101 extern void rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass);
0102 extern void _rt_mutex_lock_nest_lock(struct rt_mutex *lock, struct lockdep_map *nest_lock);
0103 #define rt_mutex_lock(lock) rt_mutex_lock_nested(lock, 0)
0104 #define rt_mutex_lock_nest_lock(lock, nest_lock) \
0105 do { \
0106 typecheck(struct lockdep_map *, &(nest_lock)->dep_map); \
0107 _rt_mutex_lock_nest_lock(lock, &(nest_lock)->dep_map); \
0108 } while (0)
0109
0110 #else
0111 extern void rt_mutex_lock(struct rt_mutex *lock);
0112 #define rt_mutex_lock_nested(lock, subclass) rt_mutex_lock(lock)
0113 #define rt_mutex_lock_nest_lock(lock, nest_lock) rt_mutex_lock(lock)
0114 #endif
0115
0116 extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
0117 extern int rt_mutex_lock_killable(struct rt_mutex *lock);
0118 extern int rt_mutex_trylock(struct rt_mutex *lock);
0119
0120 extern void rt_mutex_unlock(struct rt_mutex *lock);
0121
0122 #endif