1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Mutexes: blocking mutual exclusion locks
5 * started by Ingo Molnar:
7 * Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
11 * This is the control structure for tasks blocked on mutex, which resides
12 * on the blocked task's kernel stack:
15 struct list_head list
;
16 struct task_struct
*task
;
17 struct ww_acquire_ctx
*ww_ctx
;
18 #ifdef CONFIG_DEBUG_MUTEXES
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.
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.
32 #define MUTEX_FLAG_WAITERS 0x01
33 #define MUTEX_FLAG_HANDOFF 0x02
34 #define MUTEX_FLAG_PICKUP 0x04
36 #define MUTEX_FLAGS 0x07
39 * Internal helper function; C doesn't allow us to hide it :/
41 * DO NOT USE (outside of mutex & scheduler code).
43 static inline struct task_struct
*__mutex_owner(struct mutex
*lock
)
47 return (struct task_struct
*)(atomic_long_read(&lock
->owner
) & ~MUTEX_FLAGS
);
50 #ifdef CONFIG_DEBUG_MUTEXES
51 extern void debug_mutex_lock_common(struct mutex
*lock
,
52 struct mutex_waiter
*waiter
);
53 extern void debug_mutex_wake_waiter(struct mutex
*lock
,
54 struct mutex_waiter
*waiter
);
55 extern void debug_mutex_free_waiter(struct mutex_waiter
*waiter
);
56 extern void debug_mutex_add_waiter(struct mutex
*lock
,
57 struct mutex_waiter
*waiter
,
58 struct task_struct
*task
);
59 extern void debug_mutex_remove_waiter(struct mutex
*lock
, struct mutex_waiter
*waiter
,
60 struct task_struct
*task
);
61 extern void debug_mutex_unlock(struct mutex
*lock
);
62 extern 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 */