Linux Audio

Check our new training course

Loading...
v6.13.7
 1/* SPDX-License-Identifier: GPL-2.0 */
 2/*
 3 * Mutexes: blocking mutual exclusion locks
 4 *
 5 * started by Ingo Molnar:
 6 *
 7 *  Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
 
 
 
 8 */
 9
10/*
11 * This is the control structure for tasks blocked on mutex, which resides
12 * on the blocked task's kernel stack:
13 */
14struct mutex_waiter {
15	struct list_head	list;
16	struct task_struct	*task;
17	struct ww_acquire_ctx	*ww_ctx;
18#ifdef CONFIG_DEBUG_MUTEXES
19	void			*magic;
20#endif
21};
22
23/*
24 * @owner: contains: 'struct task_struct *' to the current lock owner,
25 * NULL means not owned. Since task_struct pointers are aligned at
26 * at least L1_CACHE_BYTES, we have low bits to store extra state.
27 *
28 * Bit0 indicates a non-empty waiter list; unlock must issue a wakeup.
29 * Bit1 indicates unlock needs to hand the lock to the top-waiter
30 * Bit2 indicates handoff has been done and we're waiting for pickup.
31 */
32#define MUTEX_FLAG_WAITERS	0x01
33#define MUTEX_FLAG_HANDOFF	0x02
34#define MUTEX_FLAG_PICKUP	0x04
35
36#define MUTEX_FLAGS		0x07
 
 
 
 
 
 
 
37
38/*
39 * Internal helper function; C doesn't allow us to hide it :/
40 *
41 * DO NOT USE (outside of mutex & scheduler code).
42 */
43static inline struct task_struct *__mutex_owner(struct mutex *lock)
44{
45	if (!lock)
46		return NULL;
47	return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS);
48}
 
 
 
 
 
 
 
49
50#ifdef CONFIG_DEBUG_MUTEXES
51extern void debug_mutex_lock_common(struct mutex *lock,
52				    struct mutex_waiter *waiter);
53extern void debug_mutex_wake_waiter(struct mutex *lock,
54				    struct mutex_waiter *waiter);
55extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
56extern void debug_mutex_add_waiter(struct mutex *lock,
57				   struct mutex_waiter *waiter,
58				   struct task_struct *task);
59extern void debug_mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
60				      struct task_struct *task);
61extern void debug_mutex_unlock(struct mutex *lock);
62extern void debug_mutex_init(struct mutex *lock, const char *name,
63			     struct lock_class_key *key);
64#else /* CONFIG_DEBUG_MUTEXES */
65# define debug_mutex_lock_common(lock, waiter)		do { } while (0)
66# define debug_mutex_wake_waiter(lock, waiter)		do { } while (0)
67# define debug_mutex_free_waiter(waiter)		do { } while (0)
68# define debug_mutex_add_waiter(lock, waiter, ti)	do { } while (0)
69# define debug_mutex_remove_waiter(lock, waiter, ti)	do { } while (0)
70# define debug_mutex_unlock(lock)			do { } while (0)
71# define debug_mutex_init(lock, name, key)		do { } while (0)
72#endif /* !CONFIG_DEBUG_MUTEXES */
v4.6
 
 1/*
 2 * Mutexes: blocking mutual exclusion locks
 3 *
 4 * started by Ingo Molnar:
 5 *
 6 *  Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
 7 *
 8 * This file contains mutex debugging related internal prototypes, for the
 9 * !CONFIG_DEBUG_MUTEXES case. Most of them are NOPs:
10 */
11
12#define spin_lock_mutex(lock, flags) \
13		do { spin_lock(lock); (void)(flags); } while (0)
14#define spin_unlock_mutex(lock, flags) \
15		do { spin_unlock(lock); (void)(flags); } while (0)
16#define mutex_remove_waiter(lock, waiter, ti) \
17		__list_del((waiter)->list.prev, (waiter)->list.next)
 
 
 
 
 
 
18
19#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
20static inline void mutex_set_owner(struct mutex *lock)
21{
22	lock->owner = current;
23}
 
 
 
 
 
 
 
24
25static inline void mutex_clear_owner(struct mutex *lock)
26{
27	lock->owner = NULL;
28}
29#else
30static inline void mutex_set_owner(struct mutex *lock)
31{
32}
33
34static inline void mutex_clear_owner(struct mutex *lock)
 
 
 
 
 
35{
 
 
 
36}
37#endif
38
39#define debug_mutex_wake_waiter(lock, waiter)		do { } while (0)
40#define debug_mutex_free_waiter(waiter)			do { } while (0)
41#define debug_mutex_add_waiter(lock, waiter, ti)	do { } while (0)
42#define debug_mutex_unlock(lock)			do { } while (0)
43#define debug_mutex_init(lock, name, key)		do { } while (0)
44
45static inline void
46debug_mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter)
47{
48}