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