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; >> 34 #ifdef CONFIG_DEBUG_RT_MUTEXES >> 35 int save_state; >> 36 const char *name, *file; >> 37 int line; >> 38 void *magic; >> 39 #endif 59 #ifdef CONFIG_DEBUG_LOCK_ALLOC 40 #ifdef CONFIG_DEBUG_LOCK_ALLOC 60 struct lockdep_map dep_map; 41 struct lockdep_map dep_map; 61 #endif 42 #endif 62 }; 43 }; 63 44 64 struct rt_mutex_waiter; 45 struct rt_mutex_waiter; 65 struct hrtimer_sleeper; 46 struct hrtimer_sleeper; 66 47 67 #ifdef CONFIG_DEBUG_RT_MUTEXES 48 #ifdef CONFIG_DEBUG_RT_MUTEXES 68 extern void rt_mutex_debug_task_free(struct ta !! 49 extern int rt_mutex_debug_check_no_locks_freed(const void *from, >> 50 unsigned long len); >> 51 extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task); 69 #else 52 #else 70 static inline void rt_mutex_debug_task_free(st !! 53 static inline int rt_mutex_debug_check_no_locks_freed(const void *from, >> 54 unsigned long len) >> 55 { >> 56 return 0; >> 57 } >> 58 # define rt_mutex_debug_check_no_locks_held(task) do { } while (0) 71 #endif 59 #endif 72 60 73 #define rt_mutex_init(mutex) \ !! 61 #ifdef CONFIG_DEBUG_RT_MUTEXES >> 62 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \ >> 63 , .name = #mutexname, .file = __FILE__, .line = __LINE__ >> 64 >> 65 # define rt_mutex_init(mutex) \ 74 do { \ 66 do { \ 75 static struct lock_class_key __key; \ 67 static struct lock_class_key __key; \ 76 __rt_mutex_init(mutex, __func__, &__ke 68 __rt_mutex_init(mutex, __func__, &__key); \ 77 } while (0) 69 } while (0) 78 70 >> 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_init(mutex) __rt_mutex_init(mutex, NULL, NULL) >> 75 # define rt_mutex_debug_task_free(t) do { } while (0) >> 76 #endif >> 77 79 #ifdef CONFIG_DEBUG_LOCK_ALLOC 78 #ifdef CONFIG_DEBUG_LOCK_ALLOC 80 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexna !! 79 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ 81 .dep_map = { !! 80 , .dep_map = { .name = #mutexname } 82 .name = #mutexname, << 83 .wait_type_inner = LD_WAIT_SLE << 84 } << 85 #else 81 #else 86 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexna 82 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) 87 #endif 83 #endif 88 84 89 #define __RT_MUTEX_INITIALIZER(mutexname) !! 85 #define __RT_MUTEX_INITIALIZER(mutexname) \ 90 { !! 86 { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ 91 .rtmutex = __RT_MUTEX_BASE_INITIALIZER !! 87 , .waiters = RB_ROOT_CACHED \ 92 __DEP_MAP_RT_MUTEX_INITIALIZER(mutexna !! 88 , .owner = NULL \ 93 } !! 89 __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \ >> 90 __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)} 94 91 95 #define DEFINE_RT_MUTEX(mutexname) \ 92 #define DEFINE_RT_MUTEX(mutexname) \ 96 struct rt_mutex mutexname = __RT_MUTEX 93 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) 97 94 >> 95 /** >> 96 * rt_mutex_is_locked - is the mutex locked >> 97 * @lock: the mutex to be queried >> 98 * >> 99 * Returns 1 if the mutex is locked, 0 if unlocked. >> 100 */ >> 101 static inline int rt_mutex_is_locked(struct rt_mutex *lock) >> 102 { >> 103 return lock->owner != NULL; >> 104 } >> 105 98 extern void __rt_mutex_init(struct rt_mutex *l 106 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key); >> 107 extern void rt_mutex_destroy(struct rt_mutex *lock); 99 108 100 #ifdef CONFIG_DEBUG_LOCK_ALLOC 109 #ifdef CONFIG_DEBUG_LOCK_ALLOC 101 extern void rt_mutex_lock_nested(struct rt_mut 110 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 111 #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 112 #else 111 extern void rt_mutex_lock(struct rt_mutex *loc 113 extern void rt_mutex_lock(struct rt_mutex *lock); 112 #define rt_mutex_lock_nested(lock, subclass) r 114 #define rt_mutex_lock_nested(lock, subclass) rt_mutex_lock(lock) 113 #define rt_mutex_lock_nest_lock(lock, nest_loc << 114 #endif 115 #endif 115 116 116 extern int rt_mutex_lock_interruptible(struct 117 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_timed_lock(struct rt_mutex *lock, >> 119 struct hrtimer_sleeper *timeout); >> 120 118 extern int rt_mutex_trylock(struct rt_mutex *l 121 extern int rt_mutex_trylock(struct rt_mutex *lock); 119 122 120 extern void rt_mutex_unlock(struct rt_mutex *l 123 extern void rt_mutex_unlock(struct rt_mutex *lock); 121 124 122 #endif 125 #endif 123 126
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.