1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * RT Mutexes: blocking mutual exclusion locks with PI support 4 * 5 * started by Ingo Molnar and Thomas Gleixner: 6 * 7 * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <[email protected]> 8 * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <[email protected]> 9 * 10 * This file contains the public data structure and API definitions. 11 */ 12 13 #ifndef __LINUX_RT_MUTEX_H 14 #define __LINUX_RT_MUTEX_H 15 16 #include <linux/linkage.h> 17 #include <linux/rbtree.h> 18 #include <linux/spinlock_types.h> 19 20 extern int max_lock_depth; /* for sysctl */ 21 22 /** 23 * The rt_mutex structure 24 * 25 * @wait_lock: spinlock to protect the structure 26 * @waiters: rbtree root to enqueue waiters in priority order; 27 * caches top-waiter (leftmost node). 28 * @owner: the mutex owner 29 */ 30 struct rt_mutex { 31 raw_spinlock_t wait_lock; 32 struct rb_root_cached waiters; 33 struct task_struct *owner; 34 #ifdef CONFIG_DEBUG_LOCK_ALLOC 35 struct lockdep_map dep_map; 36 #endif 37 }; 38 39 struct rt_mutex_waiter; 40 struct hrtimer_sleeper; 41 42 #ifdef CONFIG_DEBUG_RT_MUTEXES 43 extern void rt_mutex_debug_task_free(struct task_struct *tsk); 44 #else 45 static inline void rt_mutex_debug_task_free(struct task_struct *tsk) { } 46 #endif 47 48 #define rt_mutex_init(mutex) \ 49 do { \ 50 static struct lock_class_key __key; \ 51 __rt_mutex_init(mutex, __func__, &__key); \ 52 } while (0) 53 54 #ifdef CONFIG_DEBUG_LOCK_ALLOC 55 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ 56 .dep_map = { \ 57 .name = #mutexname, \ 58 .wait_type_inner = LD_WAIT_SLEEP, \ 59 } 60 #else 61 #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) 62 #endif 63 64 #define __RT_MUTEX_INITIALIZER(mutexname) \ 65 { \ 66 .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock), \ 67 .waiters = RB_ROOT_CACHED, \ 68 .owner = NULL, \ 69 __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ 70 } 71 72 #define DEFINE_RT_MUTEX(mutexname) \ 73 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) 74 75 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key); 76 77 #ifdef CONFIG_DEBUG_LOCK_ALLOC 78 extern void rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass); 79 #define rt_mutex_lock(lock) rt_mutex_lock_nested(lock, 0) 80 #else 81 extern void rt_mutex_lock(struct rt_mutex *lock); 82 #define rt_mutex_lock_nested(lock, subclass) rt_mutex_lock(lock) 83 #endif 84 85 extern int rt_mutex_lock_interruptible(struct rt_mutex *lock); 86 extern int rt_mutex_trylock(struct rt_mutex *lock); 87 88 extern void rt_mutex_unlock(struct rt_mutex *lock); 89 90 #endif 91