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_save(lock, flags) \
51 local_irq_save(flags); \
56 #define debug_spin_unlock_restore(lock, flags) \
60 local_irq_restore(flags); \
61 preempt_check_resched(); \
64 #define spin_lock_mutex(lock, flags) \
66 struct mutex *l = container_of(lock, struct mutex, wait_lock); \
68 DEBUG_WARN_ON(in_interrupt()); \
69 debug_spin_lock_save(&debug_mutex_lock, flags); \
71 DEBUG_WARN_ON(l->magic != l); \
74 #define spin_unlock_mutex(lock, flags) \
77 debug_spin_unlock_restore(&debug_mutex_lock, flags); \
82 if (debug_mutex_on) { \
85 if (spin_is_locked(&debug_mutex_lock)) \
86 spin_unlock(&debug_mutex_lock); \
92 if (debug_mutex_on) { \
98 #define DEBUG_WARN_ON(c) \
100 if (unlikely(c && debug_mutex_on)) { \
106 # define DEBUG_BUG_ON(c) \
113 # define SMP_DEBUG_WARN_ON(c) DEBUG_WARN_ON(c)
114 # define SMP_DEBUG_BUG_ON(c) DEBUG_BUG_ON(c)
116 # define SMP_DEBUG_WARN_ON(c) do { } while (0)
117 # define SMP_DEBUG_BUG_ON(c) do { } while (0)