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 18 21 extern int max_lock_depth; /* for sysctl */ 19 extern int max_lock_depth; /* for sysctl */ 22 20 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 /** 21 /** 50 * The rt_mutex structure 22 * The rt_mutex structure 51 * 23 * 52 * @wait_lock: spinlock to protect the struct 24 * @wait_lock: spinlock to protect the structure 53 * @waiters: rbtree root to enqueue waiters !! 25 * @wait_list: pilist head to enqueue waiters in priority order 54 * caches top-waiter (leftmost no << 55 * @owner: the mutex owner 26 * @owner: the mutex owner 56 */ 27 */ 57 struct rt_mutex { 28 struct rt_mutex { 58 struct rt_mutex_base rtmutex; !! 29 raw_spinlock_t wait_lock; 59 #ifdef CONFIG_DEBUG_LOCK_ALLOC !! 30 struct plist_head wait_list; 60 struct lockdep_map dep_map; !! 31 struct task_struct *owner; >> 32 #ifdef CONFIG_DEBUG_RT_MUTEXES >> 33 int save_state; >> 34 const char *name, *file; >> 35 int line; >> 36 void *magic; 61 #endif 37 #endif 62 }; 38 }; 63 39 64 struct rt_mutex_waiter; 40 struct rt_mutex_waiter; 65 struct hrtimer_sleeper; 41 struct hrtimer_sleeper; 66 42 67 #ifdef CONFIG_DEBUG_RT_MUTEXES 43 #ifdef CONFIG_DEBUG_RT_MUTEXES 68 extern void rt_mutex_debug_task_free(struct ta !! 44 extern int rt_mutex_debug_check_no_locks_freed(const void *from, >> 45 unsigned long len); >> 46 extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task); 69 #else 47 #else 70 static inline void rt_mutex_debug_task_free(st !! 48 static inline int rt_mutex_debug_check_no_locks_freed(const void *from, >> 49 unsigned long len) >> 50 { >> 51 return 0; >> 52 } >> 53 # define rt_mutex_debug_check_no_locks_held(task) do { } while (0) 71 #endif 54 #endif 72 55 73 #define rt_mutex_init(mutex) \ !! 56 #ifdef CONFIG_DEBUG_RT_MUTEXES 74 do { \ !! 57 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \ 75 static struct lock_class_key __key; \ !! 58 , .name = #mutexname, .file = __FILE__, .line = __LINE__ 76 __rt_mutex_init(mutex, __func__, &__ke !! 59 # define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__) 77 } while (0) !! 60 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 61 #else 86 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexna !! 62 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) >> 63 # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL) >> 64 # define rt_mutex_debug_task_free(t) do { } while (0) 87 #endif 65 #endif 88 66 89 #define __RT_MUTEX_INITIALIZER(mutexname) !! 67 #define __RT_MUTEX_INITIALIZER(mutexname) \ 90 { !! 68 { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ 91 .rtmutex = __RT_MUTEX_BASE_INITIALIZER !! 69 , .wait_list = PLIST_HEAD_INIT(mutexname.wait_list) \ 92 __DEP_MAP_RT_MUTEX_INITIALIZER(mutexna !! 70 , .owner = NULL \ 93 } !! 71 __DEBUG_RT_MUTEX_INITIALIZER(mutexname)} 94 72 95 #define DEFINE_RT_MUTEX(mutexname) \ 73 #define DEFINE_RT_MUTEX(mutexname) \ 96 struct rt_mutex mutexname = __RT_MUTEX 74 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) 97 75 98 extern void __rt_mutex_init(struct rt_mutex *l !! 76 /** >> 77 * rt_mutex_is_locked - is the mutex locked >> 78 * @lock: the mutex to be queried >> 79 * >> 80 * Returns 1 if the mutex is locked, 0 if unlocked. >> 81 */ >> 82 static inline int rt_mutex_is_locked(struct rt_mutex *lock) >> 83 { >> 84 return lock->owner != NULL; >> 85 } 99 86 100 #ifdef CONFIG_DEBUG_LOCK_ALLOC !! 87 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name); 101 extern void rt_mutex_lock_nested(struct rt_mut !! 88 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 89 110 #else << 111 extern void rt_mutex_lock(struct rt_mutex *loc 90 extern void rt_mutex_lock(struct rt_mutex *lock); 112 #define rt_mutex_lock_nested(lock, subclass) r !! 91 extern int rt_mutex_lock_interruptible(struct rt_mutex *lock, 113 #define rt_mutex_lock_nest_lock(lock, nest_loc !! 92 int detect_deadlock); 114 #endif !! 93 extern int rt_mutex_timed_lock(struct rt_mutex *lock, >> 94 struct hrtimer_sleeper *timeout, >> 95 int detect_deadlock); 115 96 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 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); >> 100 >> 101 #ifdef CONFIG_RT_MUTEXES >> 102 # define INIT_RT_MUTEXES(tsk) \ >> 103 .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters), \ >> 104 INIT_RT_MUTEX_DEBUG(tsk) >> 105 #else >> 106 # define INIT_RT_MUTEXES(tsk) >> 107 #endif 121 108 122 #endif 109 #endif 123 110
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.