]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
23f78d4a IM |
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 <mingo@redhat.com> | |
8 | * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com> | |
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> | |
fb00aca4 | 17 | #include <linux/rbtree.h> |
23f78d4a IM |
18 | #include <linux/spinlock_types.h> |
19 | ||
4f0e056f DY |
20 | extern int max_lock_depth; /* for sysctl */ |
21 | ||
45f8bde0 | 22 | /** |
23f78d4a IM |
23 | * The rt_mutex structure |
24 | * | |
25 | * @wait_lock: spinlock to protect the structure | |
a23ba907 DB |
26 | * @waiters: rbtree root to enqueue waiters in priority order; |
27 | * caches top-waiter (leftmost node). | |
23f78d4a IM |
28 | * @owner: the mutex owner |
29 | */ | |
30 | struct rt_mutex { | |
d209d74d | 31 | raw_spinlock_t wait_lock; |
a23ba907 | 32 | struct rb_root_cached waiters; |
23f78d4a | 33 | struct task_struct *owner; |
f5694788 PZ |
34 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
35 | struct lockdep_map dep_map; | |
36 | #endif | |
23f78d4a IM |
37 | }; |
38 | ||
39 | struct rt_mutex_waiter; | |
40 | struct hrtimer_sleeper; | |
41 | ||
e7eebaf6 | 42 | #ifdef CONFIG_DEBUG_RT_MUTEXES |
8188d74e | 43 | extern void rt_mutex_debug_task_free(struct task_struct *tsk); |
e7eebaf6 | 44 | #else |
8188d74e | 45 | static inline void rt_mutex_debug_task_free(struct task_struct *tsk) { } |
e7eebaf6 IM |
46 | #endif |
47 | ||
199cacd1 | 48 | #define rt_mutex_init(mutex) \ |
f5694788 PZ |
49 | do { \ |
50 | static struct lock_class_key __key; \ | |
51 | __rt_mutex_init(mutex, __func__, &__key); \ | |
52 | } while (0) | |
53 | ||
f5694788 PZ |
54 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
55 | #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ | |
56 | , .dep_map = { .name = #mutexname } | |
57 | #else | |
58 | #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) | |
59 | #endif | |
60 | ||
23f78d4a | 61 | #define __RT_MUTEX_INITIALIZER(mutexname) \ |
d209d74d | 62 | { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ |
a23ba907 | 63 | , .waiters = RB_ROOT_CACHED \ |
23f78d4a | 64 | , .owner = NULL \ |
f5694788 | 65 | __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)} |
23f78d4a IM |
66 | |
67 | #define DEFINE_RT_MUTEX(mutexname) \ | |
68 | struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) | |
69 | ||
45f8bde0 | 70 | /** |
23f78d4a IM |
71 | * rt_mutex_is_locked - is the mutex locked |
72 | * @lock: the mutex to be queried | |
73 | * | |
74 | * Returns 1 if the mutex is locked, 0 if unlocked. | |
75 | */ | |
76 | static inline int rt_mutex_is_locked(struct rt_mutex *lock) | |
77 | { | |
78 | return lock->owner != NULL; | |
79 | } | |
80 | ||
f5694788 | 81 | extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key); |
23f78d4a | 82 | |
62cedf3e PR |
83 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
84 | extern void rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass); | |
85 | #define rt_mutex_lock(lock) rt_mutex_lock_nested(lock, 0) | |
86 | #else | |
23f78d4a | 87 | extern void rt_mutex_lock(struct rt_mutex *lock); |
62cedf3e PR |
88 | #define rt_mutex_lock_nested(lock, subclass) rt_mutex_lock(lock) |
89 | #endif | |
90 | ||
c051b21f | 91 | extern int rt_mutex_lock_interruptible(struct rt_mutex *lock); |
23f78d4a IM |
92 | extern int rt_mutex_trylock(struct rt_mutex *lock); |
93 | ||
94 | extern void rt_mutex_unlock(struct rt_mutex *lock); | |
95 | ||
23f78d4a | 96 | #endif |