1 #ifndef __LINUX_SPINLOCK_API_SMP_H
2 #define __LINUX_SPINLOCK_API_SMP_H
4 #ifndef __LINUX_SPINLOCK_H
5 # error "please don't include this file directly"
9 * include/linux/spinlock_api_smp.h
11 * spinlock API declarations on SMP (and debug)
12 * (implemented in kernel/spinlock.c)
14 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
15 * Released under the General Public License (GPL).
18 int in_lock_functions(unsigned long addr
);
20 #define assert_raw_spin_locked(x) BUG_ON(!raw_spin_is_locked(x))
22 void __lockfunc
_raw_spin_lock(raw_spinlock_t
*lock
) __acquires(lock
);
23 void __lockfunc
_raw_spin_lock_nested(raw_spinlock_t
*lock
, int subclass
)
26 _raw_spin_lock_nest_lock(raw_spinlock_t
*lock
, struct lockdep_map
*map
)
28 void __lockfunc
_raw_spin_lock_bh(raw_spinlock_t
*lock
) __acquires(lock
);
29 void __lockfunc
_raw_spin_lock_irq(raw_spinlock_t
*lock
)
32 unsigned long __lockfunc
_raw_spin_lock_irqsave(raw_spinlock_t
*lock
)
34 unsigned long __lockfunc
35 _raw_spin_lock_irqsave_nested(raw_spinlock_t
*lock
, int subclass
)
37 int __lockfunc
_raw_spin_trylock(raw_spinlock_t
*lock
);
38 int __lockfunc
_raw_spin_trylock_bh(raw_spinlock_t
*lock
);
39 void __lockfunc
_raw_spin_unlock(raw_spinlock_t
*lock
) __releases(lock
);
40 void __lockfunc
_raw_spin_unlock_bh(raw_spinlock_t
*lock
) __releases(lock
);
41 void __lockfunc
_raw_spin_unlock_irq(raw_spinlock_t
*lock
) __releases(lock
);
43 _raw_spin_unlock_irqrestore(raw_spinlock_t
*lock
, unsigned long flags
)
46 #ifdef CONFIG_INLINE_SPIN_LOCK
47 #define _raw_spin_lock(lock) __raw_spin_lock(lock)
50 #ifdef CONFIG_INLINE_SPIN_LOCK_BH
51 #define _raw_spin_lock_bh(lock) __raw_spin_lock_bh(lock)
54 #ifdef CONFIG_INLINE_SPIN_LOCK_IRQ
55 #define _raw_spin_lock_irq(lock) __raw_spin_lock_irq(lock)
58 #ifdef CONFIG_INLINE_SPIN_LOCK_IRQSAVE
59 #define _raw_spin_lock_irqsave(lock) __raw_spin_lock_irqsave(lock)
62 #ifdef CONFIG_INLINE_SPIN_TRYLOCK
63 #define _raw_spin_trylock(lock) __raw_spin_trylock(lock)
66 #ifdef CONFIG_INLINE_SPIN_TRYLOCK_BH
67 #define _raw_spin_trylock_bh(lock) __raw_spin_trylock_bh(lock)
70 #ifndef CONFIG_UNINLINE_SPIN_UNLOCK
71 #define _raw_spin_unlock(lock) __raw_spin_unlock(lock)
74 #ifdef CONFIG_INLINE_SPIN_UNLOCK_BH
75 #define _raw_spin_unlock_bh(lock) __raw_spin_unlock_bh(lock)
78 #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQ
79 #define _raw_spin_unlock_irq(lock) __raw_spin_unlock_irq(lock)
82 #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE
83 #define _raw_spin_unlock_irqrestore(lock, flags) __raw_spin_unlock_irqrestore(lock, flags)
86 static inline int __raw_spin_trylock(raw_spinlock_t
*lock
)
89 if (do_raw_spin_trylock(lock
)) {
90 spin_acquire(&lock
->dep_map
, 0, 1, _RET_IP_
);
98 * If lockdep is enabled then we use the non-preemption spin-ops
99 * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are
100 * not re-enabled during lock-acquire (which the preempt-spin-ops do):
102 #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
104 static inline unsigned long __raw_spin_lock_irqsave(raw_spinlock_t
*lock
)
108 local_irq_save(flags
);
110 spin_acquire(&lock
->dep_map
, 0, 0, _RET_IP_
);
112 * On lockdep we dont want the hand-coded irq-enable of
113 * do_raw_spin_lock_flags() code, because lockdep assumes
114 * that interrupts are not re-enabled during lock-acquire:
116 #ifdef CONFIG_LOCKDEP
117 LOCK_CONTENDED(lock
, do_raw_spin_trylock
, do_raw_spin_lock
);
119 do_raw_spin_lock_flags(lock
, &flags
);
124 static inline void __raw_spin_lock_irq(raw_spinlock_t
*lock
)
128 spin_acquire(&lock
->dep_map
, 0, 0, _RET_IP_
);
129 LOCK_CONTENDED(lock
, do_raw_spin_trylock
, do_raw_spin_lock
);
132 static inline void __raw_spin_lock_bh(raw_spinlock_t
*lock
)
134 __local_bh_disable_ip(_RET_IP_
, SOFTIRQ_LOCK_OFFSET
);
135 spin_acquire(&lock
->dep_map
, 0, 0, _RET_IP_
);
136 LOCK_CONTENDED(lock
, do_raw_spin_trylock
, do_raw_spin_lock
);
139 static inline void __raw_spin_lock(raw_spinlock_t
*lock
)
142 spin_acquire(&lock
->dep_map
, 0, 0, _RET_IP_
);
143 LOCK_CONTENDED(lock
, do_raw_spin_trylock
, do_raw_spin_lock
);
146 #endif /* !CONFIG_GENERIC_LOCKBREAK || CONFIG_DEBUG_LOCK_ALLOC */
148 static inline void __raw_spin_unlock(raw_spinlock_t
*lock
)
150 spin_release(&lock
->dep_map
, 1, _RET_IP_
);
151 do_raw_spin_unlock(lock
);
155 static inline void __raw_spin_unlock_irqrestore(raw_spinlock_t
*lock
,
158 spin_release(&lock
->dep_map
, 1, _RET_IP_
);
159 do_raw_spin_unlock(lock
);
160 local_irq_restore(flags
);
164 static inline void __raw_spin_unlock_irq(raw_spinlock_t
*lock
)
166 spin_release(&lock
->dep_map
, 1, _RET_IP_
);
167 do_raw_spin_unlock(lock
);
172 static inline void __raw_spin_unlock_bh(raw_spinlock_t
*lock
)
174 spin_release(&lock
->dep_map
, 1, _RET_IP_
);
175 do_raw_spin_unlock(lock
);
176 __local_bh_enable_ip(_RET_IP_
, SOFTIRQ_LOCK_OFFSET
);
179 static inline int __raw_spin_trylock_bh(raw_spinlock_t
*lock
)
181 __local_bh_disable_ip(_RET_IP_
, SOFTIRQ_LOCK_OFFSET
);
182 if (do_raw_spin_trylock(lock
)) {
183 spin_acquire(&lock
->dep_map
, 0, 1, _RET_IP_
);
186 __local_bh_enable_ip(_RET_IP_
, SOFTIRQ_LOCK_OFFSET
);
190 #include <linux/rwlock_api_smp.h>
192 #endif /* __LINUX_SPINLOCK_API_SMP_H */