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/rbtree.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 * @waiters: rbtree root to enqueue waiters in priority order 54 * caches top-waiter (leftmost no !! 26 * @waiters_leftmost: top waiter 55 * @owner: the mutex owner 27 * @owner: the mutex owner 56 */ 28 */ 57 struct rt_mutex { 29 struct rt_mutex { 58 struct rt_mutex_base rtmutex; !! 30 raw_spinlock_t wait_lock; 59 #ifdef CONFIG_DEBUG_LOCK_ALLOC !! 31 struct rb_root waiters; 60 struct lockdep_map dep_map; !! 32 struct rb_node *waiters_leftmost; >> 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; 61 #endif 39 #endif 62 }; 40 }; 63 41 64 struct rt_mutex_waiter; 42 struct rt_mutex_waiter; 65 struct hrtimer_sleeper; 43 struct hrtimer_sleeper; 66 44 67 #ifdef CONFIG_DEBUG_RT_MUTEXES 45 #ifdef CONFIG_DEBUG_RT_MUTEXES 68 extern void rt_mutex_debug_task_free(struct ta !! 46 extern int rt_mutex_debug_check_no_locks_freed(const void *from, >> 47 unsigned long len); >> 48 extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task); 69 #else 49 #else 70 static inline void rt_mutex_debug_task_free(st !! 50 static inline int rt_mutex_debug_check_no_locks_freed(const void *from, >> 51 unsigned long len) >> 52 { >> 53 return 0; >> 54 } >> 55 # define rt_mutex_debug_check_no_locks_held(task) do { } while (0) 71 #endif 56 #endif 72 57 73 #define rt_mutex_init(mutex) \ !! 58 #ifdef CONFIG_DEBUG_RT_MUTEXES 74 do { \ !! 59 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \ 75 static struct lock_class_key __key; \ !! 60 , .name = #mutexname, .file = __FILE__, .line = __LINE__ 76 __rt_mutex_init(mutex, __func__, &__ke !! 61 # define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__) 77 } while (0) !! 62 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 63 #else 86 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexna !! 64 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) >> 65 # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL) >> 66 # define rt_mutex_debug_task_free(t) do { } while (0) 87 #endif 67 #endif 88 68 89 #define __RT_MUTEX_INITIALIZER(mutexname) !! 69 #define __RT_MUTEX_INITIALIZER(mutexname) \ 90 { !! 70 { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ 91 .rtmutex = __RT_MUTEX_BASE_INITIALIZER !! 71 , .waiters = RB_ROOT \ 92 __DEP_MAP_RT_MUTEX_INITIALIZER(mutexna !! 72 , .owner = NULL \ 93 } !! 73 __DEBUG_RT_MUTEX_INITIALIZER(mutexname)} 94 74 95 #define DEFINE_RT_MUTEX(mutexname) \ 75 #define DEFINE_RT_MUTEX(mutexname) \ 96 struct rt_mutex mutexname = __RT_MUTEX 76 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) 97 77 98 extern void __rt_mutex_init(struct rt_mutex *l !! 78 /** >> 79 * rt_mutex_is_locked - is the mutex locked >> 80 * @lock: the mutex to be queried >> 81 * >> 82 * Returns 1 if the mutex is locked, 0 if unlocked. >> 83 */ >> 84 static inline int rt_mutex_is_locked(struct rt_mutex *lock) >> 85 { >> 86 return lock->owner != NULL; >> 87 } 99 88 100 #ifdef CONFIG_DEBUG_LOCK_ALLOC !! 89 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name); 101 extern void rt_mutex_lock_nested(struct rt_mut !! 90 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 91 110 #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 << 113 #define rt_mutex_lock_nest_lock(lock, nest_loc << 114 #endif << 115 << 116 extern int rt_mutex_lock_interruptible(struct 93 extern int rt_mutex_lock_interruptible(struct rt_mutex *lock); 117 extern int rt_mutex_lock_killable(struct rt_mu !! 94 extern int rt_mutex_timed_lock(struct rt_mutex *lock, >> 95 struct hrtimer_sleeper *timeout); >> 96 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.