• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_MUTEX_TYPES_H
3 #define __LINUX_MUTEX_TYPES_H
4 
5 #include <linux/atomic.h>
6 #include <linux/lockdep_types.h>
7 #include <linux/osq_lock.h>
8 #include <linux/spinlock_types.h>
9 #include <linux/types.h>
10 #include <linux/android_vendor.h>
11 
12 #ifndef CONFIG_PREEMPT_RT
13 
14 /*
15  * Simple, straightforward mutexes with strict semantics:
16  *
17  * - only one task can hold the mutex at a time
18  * - only the owner can unlock the mutex
19  * - multiple unlocks are not permitted
20  * - recursive locking is not permitted
21  * - a mutex object must be initialized via the API
22  * - a mutex object must not be initialized via memset or copying
23  * - task may not exit with mutex held
24  * - memory areas where held locks reside must not be freed
25  * - held mutexes must not be reinitialized
26  * - mutexes may not be used in hardware or software interrupt
27  *   contexts such as tasklets and timers
28  *
29  * These semantics are fully enforced when DEBUG_MUTEXES is
30  * enabled. Furthermore, besides enforcing the above rules, the mutex
31  * debugging code also implements a number of additional features
32  * that make lock debugging easier and faster:
33  *
34  * - uses symbolic names of mutexes, whenever they are printed in debug output
35  * - point-of-acquire tracking, symbolic lookup of function names
36  * - list of all locks held in the system, printout of them
37  * - owner tracking
38  * - detects self-recursing locks and prints out all relevant info
39  * - detects multi-task circular deadlocks and prints out all affected
40  *   locks and tasks (and only those tasks)
41  */
42 struct mutex {
43 	atomic_long_t		owner;
44 	raw_spinlock_t		wait_lock;
45 #ifdef CONFIG_MUTEX_SPIN_ON_OWNER
46 	struct optimistic_spin_queue osq; /* Spinner MCS lock */
47 #endif
48 	struct list_head	wait_list;
49 #ifdef CONFIG_DEBUG_MUTEXES
50 	void			*magic;
51 #endif
52 #ifdef CONFIG_DEBUG_LOCK_ALLOC
53 	struct lockdep_map	dep_map;
54 #endif
55 	ANDROID_OEM_DATA_ARRAY(1, 2);
56 };
57 
58 #else /* !CONFIG_PREEMPT_RT */
59 /*
60  * Preempt-RT variant based on rtmutexes.
61  */
62 #include <linux/rtmutex.h>
63 
64 struct mutex {
65 	struct rt_mutex_base	rtmutex;
66 #ifdef CONFIG_DEBUG_LOCK_ALLOC
67 	struct lockdep_map	dep_map;
68 #endif
69 	ANDROID_OEM_DATA_ARRAY(1, 2);
70 };
71 
72 #endif /* CONFIG_PREEMPT_RT */
73 
74 #endif /* __LINUX_MUTEX_TYPES_H */
75