2 * Mutexes: blocking mutual exclusion locks
4 * started by Ingo Molnar:
6 * Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
8 * This file contains mutex debugging related internal declarations,
9 * prototypes and inline functions, for the CONFIG_DEBUG_MUTEXES case.
10 * More details are in kernel/mutex-debug.c.
13 extern spinlock_t debug_mutex_lock
;
14 extern struct list_head debug_mutex_held_locks
;
15 extern int debug_mutex_on
;
18 * In the debug case we carry the caller's instruction pointer into
19 * other functions, but we dont want the function argument overhead
20 * in the nondebug case - hence these macros:
22 #define __IP_DECL__ , unsigned long ip
24 #define __RET_IP__ , (unsigned long)__builtin_return_address(0)
27 * This must be called with lock->wait_lock held.
29 extern void debug_mutex_set_owner(struct mutex
*lock
,
30 struct thread_info
*new_owner __IP_DECL__
);
32 static inline void debug_mutex_clear_owner(struct mutex
*lock
)
37 extern void debug_mutex_init_waiter(struct mutex_waiter
*waiter
);
38 extern void debug_mutex_wake_waiter(struct mutex
*lock
,
39 struct mutex_waiter
*waiter
);
40 extern void debug_mutex_free_waiter(struct mutex_waiter
*waiter
);
41 extern void debug_mutex_add_waiter(struct mutex
*lock
,
42 struct mutex_waiter
*waiter
,
43 struct thread_info
*ti __IP_DECL__
);
44 extern void mutex_remove_waiter(struct mutex
*lock
, struct mutex_waiter
*waiter
,
45 struct thread_info
*ti
);
46 extern void debug_mutex_unlock(struct mutex
*lock
);
47 extern void debug_mutex_init(struct mutex
*lock
, const char *name
);
49 #define debug_spin_lock(lock) \
51 local_irq_disable(); \
56 #define debug_spin_unlock(lock) \
61 preempt_check_resched(); \
64 #define debug_spin_lock_save(lock, flags) \
66 local_irq_save(flags); \
71 #define debug_spin_lock_restore(lock, flags) \
75 local_irq_restore(flags); \
76 preempt_check_resched(); \
79 #define spin_lock_mutex(lock) \
81 struct mutex *l = container_of(lock, struct mutex, wait_lock); \
83 DEBUG_WARN_ON(in_interrupt()); \
84 debug_spin_lock(&debug_mutex_lock); \
86 DEBUG_WARN_ON(l->magic != l); \
89 #define spin_unlock_mutex(lock) \
92 debug_spin_unlock(&debug_mutex_lock); \
97 if (debug_mutex_on) { \
100 if (spin_is_locked(&debug_mutex_lock)) \
101 spin_unlock(&debug_mutex_lock); \
105 #define DEBUG_BUG() \
107 if (debug_mutex_on) { \
113 #define DEBUG_WARN_ON(c) \
115 if (unlikely(c && debug_mutex_on)) { \
121 # define DEBUG_BUG_ON(c) \
128 # define SMP_DEBUG_WARN_ON(c) DEBUG_WARN_ON(c)
129 # define SMP_DEBUG_BUG_ON(c) DEBUG_BUG_ON(c)
131 # define SMP_DEBUG_WARN_ON(c) do { } while (0)
132 # define SMP_DEBUG_BUG_ON(c) do { } while (0)