blob: d4841ed8215b755ae2a291245687187479d4d27c [file] [log] [blame]
Ingo Molnarfb1c8f92005-09-10 00:25:56 -07001#ifndef __LINUX_SPINLOCK_UP_H
2#define __LINUX_SPINLOCK_UP_H
3
4#ifndef __LINUX_SPINLOCK_H
5# error "please don't include this file directly"
6#endif
7
8/*
9 * include/linux/spinlock_up.h - UP-debug version of spinlocks.
10 *
11 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
12 * Released under the General Public License (GPL).
13 *
14 * In the debug case, 1 means unlocked, 0 means locked. (the values
15 * are inverted, to catch initialization bugs)
16 *
17 * No atomicity anywhere, we are on UP.
18 */
19
20#ifdef CONFIG_DEBUG_SPINLOCK
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070021#define __raw_spin_is_locked(x) ((x)->slock == 0)
22
23static inline void __raw_spin_lock(raw_spinlock_t *lock)
24{
25 lock->slock = 0;
26}
27
28static inline void
29__raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
30{
31 local_irq_save(flags);
32 lock->slock = 0;
33}
34
35static inline int __raw_spin_trylock(raw_spinlock_t *lock)
36{
37 char oldval = lock->slock;
38
39 lock->slock = 0;
40
41 return oldval > 0;
42}
43
44static inline void __raw_spin_unlock(raw_spinlock_t *lock)
45{
46 lock->slock = 1;
47}
48
49/*
50 * Read-write spinlocks. No debug version.
51 */
52#define __raw_read_lock(lock) do { (void)(lock); } while (0)
53#define __raw_write_lock(lock) do { (void)(lock); } while (0)
54#define __raw_read_trylock(lock) ({ (void)(lock); 1; })
55#define __raw_write_trylock(lock) ({ (void)(lock); 1; })
56#define __raw_read_unlock(lock) do { (void)(lock); } while (0)
57#define __raw_write_unlock(lock) do { (void)(lock); } while (0)
58
59#else /* DEBUG_SPINLOCK */
60#define __raw_spin_is_locked(lock) ((void)(lock), 0)
61/* for sched.c and kernel_lock.c: */
62# define __raw_spin_lock(lock) do { (void)(lock); } while (0)
Benjamin Herrenschmidt04dce7d2009-06-10 16:59:46 +100063# define __raw_spin_lock_flags(lock, flags) do { (void)(lock); } while (0)
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070064# define __raw_spin_unlock(lock) do { (void)(lock); } while (0)
65# define __raw_spin_trylock(lock) ({ (void)(lock); 1; })
66#endif /* DEBUG_SPINLOCK */
67
Nick Piggin95c354f2008-01-30 13:31:20 +010068#define __raw_spin_is_contended(lock) (((void)(lock), 0))
69
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070070#define __raw_read_can_lock(lock) (((void)(lock), 1))
71#define __raw_write_can_lock(lock) (((void)(lock), 1))
72
73#define __raw_spin_unlock_wait(lock) \
74 do { cpu_relax(); } while (__raw_spin_is_locked(lock))
75
76#endif /* __LINUX_SPINLOCK_UP_H */