1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * RT Mutexes: blocking mutual exclusion locks 3 * RT Mutexes: blocking mutual exclusion locks with PI support 4 * 4 * 5 * started by Ingo Molnar and Thomas Gleixner: 5 * started by Ingo Molnar and Thomas Gleixner: 6 * 6 * 7 * Copyright (C) 2004-2006 Red Hat, Inc., Ing 7 * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com> 8 * Copyright (C) 2006, Timesys Corp., Thomas 8 * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com> 9 * 9 * 10 * This file contains the public data structur 10 * This file contains the public data structure and API definitions. 11 */ 11 */ 12 12 13 #ifndef __LINUX_RT_MUTEX_H 13 #ifndef __LINUX_RT_MUTEX_H 14 #define __LINUX_RT_MUTEX_H 14 #define __LINUX_RT_MUTEX_H 15 15 16 #include <linux/compiler.h> << 17 #include <linux/linkage.h> 16 #include <linux/linkage.h> 18 #include <linux/rbtree_types.h> !! 17 #include <linux/rbtree.h> 19 #include <linux/spinlock_types_raw.h> !! 18 #include <linux/spinlock_types.h> 20 19 21 extern int max_lock_depth; /* for sysctl */ 20 extern int max_lock_depth; /* for sysctl */ 22 21 23 struct rt_mutex_base { << 24 raw_spinlock_t wait_lock; << 25 struct rb_root_cached waiters; << 26 struct task_struct *owner; << 27 }; << 28 << 29 #define __RT_MUTEX_BASE_INITIALIZER(rtbasename << 30 { << 31 .wait_lock = __RAW_SPIN_LOCK_UNLOCKED( << 32 .waiters = RB_ROOT_CACHED, << 33 .owner = NULL << 34 } << 35 << 36 /** << 37 * rt_mutex_base_is_locked - is the rtmutex lo << 38 * @lock: the mutex to be queried << 39 * << 40 * Returns true if the mutex is locked, false << 41 */ << 42 static inline bool rt_mutex_base_is_locked(str << 43 { << 44 return READ_ONCE(lock->owner) != NULL; << 45 } << 46 << 47 extern void rt_mutex_base_init(struct rt_mutex << 48 << 49 /** 22 /** 50 * The rt_mutex structure 23 * The rt_mutex structure 51 * 24 * 52 * @wait_lock: spinlock to protect the struct 25 * @wait_lock: spinlock to protect the structure 53 * @waiters: rbtree root to enqueue waiters 26 * @waiters: rbtree root to enqueue waiters in priority order; 54 * caches top-waiter (leftmost no 27 * caches top-waiter (leftmost node). 55 * @owner: the mutex owner 28 * @owner: the mutex owner 56 */ 29 */ 57 struct rt_mutex { 30 struct rt_mutex { 58 struct rt_mutex_base rtmutex; !! 31 raw_spinlock_t wait_lock; >> 32 struct rb_root_cached waiters; >> 33 struct task_struct *owner; 59 #ifdef CONFIG_DEBUG_LOCK_ALLOC 34 #ifdef CONFIG_DEBUG_LOCK_ALLOC 60 struct lockdep_map dep_map; 35 struct lockdep_map dep_map; 61 #endif 36 #endif 62 }; 37 }; 63 38 64 struct rt_mutex_waiter; 39 struct rt_mutex_waiter; 65 struct hrtimer_sleeper; 40 struct hrtimer_sleeper; 66 41 67 #ifdef CONFIG_DEBUG_RT_MUTEXES 42 #ifdef CONFIG_DEBUG_RT_MUTEXES 68 extern void rt_mutex_debug_task_free(struct ta 43 extern void rt_mutex_debug_task_free(struct task_struct *tsk); 69 #else 44 #else 70 static inline void rt_mutex_debug_task_free(st 45 static inline void rt_mutex_debug_task_free(struct task_struct *tsk) { } 71 #endif 46 #endif 72 47 73 #define rt_mutex_init(mutex) \ 48 #define rt_mutex_init(mutex) \ 74 do { \ 49 do { \ 75 static struct lock_class_key __key; \ 50 static struct lock_class_key __key; \ 76 __rt_mutex_init(mutex, __func__, &__ke 51 __rt_mutex_init(mutex, __func__, &__key); \ 77 } while (0) 52 } while (0) 78 53 79 #ifdef CONFIG_DEBUG_LOCK_ALLOC 54 #ifdef CONFIG_DEBUG_LOCK_ALLOC 80 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexna 55 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ 81 .dep_map = { 56 .dep_map = { \ 82 .name = #mutexname, 57 .name = #mutexname, \ 83 .wait_type_inner = LD_WAIT_SLE 58 .wait_type_inner = LD_WAIT_SLEEP, \ 84 } 59 } 85 #else 60 #else 86 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexna 61 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) 87 #endif 62 #endif 88 63 89 #define __RT_MUTEX_INITIALIZER(mutexname) 64 #define __RT_MUTEX_INITIALIZER(mutexname) \ 90 { 65 { \ 91 .rtmutex = __RT_MUTEX_BASE_INITIALIZER !! 66 .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock), \ >> 67 .waiters = RB_ROOT_CACHED, \ >> 68 .owner = NULL, \ 92 __DEP_MAP_RT_MUTEX_INITIALIZER(mutexna 69 __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ 93 } 70 } 94 71 95 #define DEFINE_RT_MUTEX(mutexname) \ 72 #define DEFINE_RT_MUTEX(mutexname) \ 96 struct rt_mutex mutexname = __RT_MUTEX 73 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) 97 74 >> 75 /** >> 76 * rt_mutex_is_locked - is the mutex locked >> 77 * @lock: the mutex to be queried >> 78 * >> 79 * Returns 1 if the mutex is locked, 0 if unlocked. >> 80 */ >> 81 static inline int rt_mutex_is_locked(struct rt_mutex *lock) >> 82 { >> 83 return lock->owner != NULL; >> 84 } >> 85 98 extern void __rt_mutex_init(struct rt_mutex *l 86 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key); 99 87 100 #ifdef CONFIG_DEBUG_LOCK_ALLOC 88 #ifdef CONFIG_DEBUG_LOCK_ALLOC 101 extern void rt_mutex_lock_nested(struct rt_mut 89 extern void rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass); 102 extern void _rt_mutex_lock_nest_lock(struct rt << 103 #define rt_mutex_lock(lock) rt_mutex_lock_nest 90 #define rt_mutex_lock(lock) rt_mutex_lock_nested(lock, 0) 104 #define rt_mutex_lock_nest_lock(lock, nest_loc << 105 do { << 106 typecheck(struct lockdep_map * << 107 _rt_mutex_lock_nest_lock(lock, << 108 } while (0) << 109 << 110 #else 91 #else 111 extern void rt_mutex_lock(struct rt_mutex *loc 92 extern void rt_mutex_lock(struct rt_mutex *lock); 112 #define rt_mutex_lock_nested(lock, subclass) r 93 #define rt_mutex_lock_nested(lock, subclass) rt_mutex_lock(lock) 113 #define rt_mutex_lock_nest_lock(lock, nest_loc << 114 #endif 94 #endif 115 95 116 extern int rt_mutex_lock_interruptible(struct 96 extern int rt_mutex_lock_interruptible(struct rt_mutex *lock); 117 extern int rt_mutex_lock_killable(struct rt_mu << 118 extern int rt_mutex_trylock(struct rt_mutex *l 97 extern int rt_mutex_trylock(struct rt_mutex *lock); 119 98 120 extern void rt_mutex_unlock(struct rt_mutex *l 99 extern void rt_mutex_unlock(struct rt_mutex *lock); 121 100 122 #endif 101 #endif 123 102
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.