Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / include / linux / spinlock.h
blob8bb2d1c5d10dc1771dd2daec1fbf6f98558b62e1
1 #ifndef __LINUX_SPINLOCK_H
2 #define __LINUX_SPINLOCK_H
4 #include <linux/config.h>
6 /*
7 * These are the generic versions of the spinlocks and read-write
8 * locks..
9 */
10 #define spin_lock_irqsave(lock, flags) do { local_irq_save(flags); spin_lock(lock); } while (0)
11 #define spin_lock_irq(lock) do { local_irq_disable(); spin_lock(lock); } while (0)
12 #define spin_lock_bh(lock) do { local_bh_disable(); spin_lock(lock); } while (0)
14 #define read_lock_irqsave(lock, flags) do { local_irq_save(flags); read_lock(lock); } while (0)
15 #define read_lock_irq(lock) do { local_irq_disable(); read_lock(lock); } while (0)
16 #define read_lock_bh(lock) do { local_bh_disable(); read_lock(lock); } while (0)
18 #define write_lock_irqsave(lock, flags) do { local_irq_save(flags); write_lock(lock); } while (0)
19 #define write_lock_irq(lock) do { local_irq_disable(); write_lock(lock); } while (0)
20 #define write_lock_bh(lock) do { local_bh_disable(); write_lock(lock); } while (0)
22 #define spin_unlock_irqrestore(lock, flags) do { spin_unlock(lock); local_irq_restore(flags); } while (0)
23 #define spin_unlock_irq(lock) do { spin_unlock(lock); local_irq_enable(); } while (0)
24 #define spin_unlock_bh(lock) do { spin_unlock(lock); local_bh_enable(); } while (0)
26 #define read_unlock_irqrestore(lock, flags) do { read_unlock(lock); local_irq_restore(flags); } while (0)
27 #define read_unlock_irq(lock) do { read_unlock(lock); local_irq_enable(); } while (0)
28 #define read_unlock_bh(lock) do { read_unlock(lock); local_bh_enable(); } while (0)
30 #define write_unlock_irqrestore(lock, flags) do { write_unlock(lock); local_irq_restore(flags); } while (0)
31 #define write_unlock_irq(lock) do { write_unlock(lock); local_irq_enable(); } while (0)
32 #define write_unlock_bh(lock) do { write_unlock(lock); local_bh_enable(); } while (0)
34 #ifdef CONFIG_SMP
35 #include <asm/spinlock.h>
37 #else /* !SMP */
39 #define DEBUG_SPINLOCKS 0 /* 0 == no debugging, 1 == maintain lock state, 2 == full debug */
41 #if (DEBUG_SPINLOCKS < 1)
43 #define atomic_dec_and_lock(atomic,lock) atomic_dec_and_test(atomic)
46 * Your basic spinlocks, allowing only a single CPU anywhere
48 * Most gcc versions have a nasty bug with empty initializers.
50 #if (__GNUC__ > 2)
51 typedef struct { } spinlock_t;
52 #define SPIN_LOCK_UNLOCKED (spinlock_t) { }
53 #else
54 typedef struct { int gcc_is_buggy; } spinlock_t;
55 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
56 #endif
58 #define spin_lock_init(lock) do { } while(0)
59 #define spin_lock(lock) (void)(lock) /* Not "unused variable". */
60 #define spin_is_locked(lock) (0)
61 #define spin_trylock(lock) ({1; })
62 #define spin_unlock_wait(lock) do { } while(0)
63 #define spin_unlock(lock) do { } while(0)
65 #elif (DEBUG_SPINLOCKS < 2)
67 typedef struct {
68 volatile unsigned long lock;
69 } spinlock_t;
70 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
72 #define spin_lock_init(x) do { (x)->lock = 0; } while (0)
73 #define spin_is_locked(lock) (test_bit(0,(lock)))
74 #define spin_trylock(lock) (!test_and_set_bit(0,(lock)))
76 #define spin_lock(x) do { (x)->lock = 1; } while (0)
77 #define spin_unlock_wait(x) do { } while (0)
78 #define spin_unlock(x) do { (x)->lock = 0; } while (0)
80 #else /* (DEBUG_SPINLOCKS >= 2) */
82 typedef struct {
83 volatile unsigned long lock;
84 volatile unsigned int babble;
85 const char *module;
86 } spinlock_t;
87 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0, 25, __BASE_FILE__ }
89 #include <linux/kernel.h>
91 #define spin_lock_init(x) do { (x)->lock = 0; } while (0)
92 #define spin_is_locked(lock) (test_bit(0,(lock)))
93 #define spin_trylock(lock) (!test_and_set_bit(0,(lock)))
95 #define spin_lock(x) do {unsigned long __spinflags; save_flags(__spinflags); cli(); if ((x)->lock&&(x)->babble) {printk("%s:%d: spin_lock(%s:%p) already locked\n", __BASE_FILE__,__LINE__, (x)->module, (x));(x)->babble--;} (x)->lock = 1; restore_flags(__spinflags);} while (0)
96 #define spin_unlock_wait(x) do {unsigned long __spinflags; save_flags(__spinflags); cli(); if ((x)->lock&&(x)->babble) {printk("%s:%d: spin_unlock_wait(%s:%p) deadlock\n", __BASE_FILE__,__LINE__, (x)->module, (x));(x)->babble--;} restore_flags(__spinflags);} while (0)
97 #define spin_unlock(x) do {unsigned long __spinflags; save_flags(__spinflags); cli(); if (!(x)->lock&&(x)->babble) {printk("%s:%d: spin_unlock(%s:%p) not locked\n", __BASE_FILE__,__LINE__, (x)->module, (x));(x)->babble--;} (x)->lock = 0; restore_flags(__spinflags);} while (0)
99 #endif /* DEBUG_SPINLOCKS */
102 * Read-write spinlocks, allowing multiple readers
103 * but only one writer.
105 * NOTE! it is quite common to have readers in interrupts
106 * but no interrupt writers. For those circumstances we
107 * can "mix" irq-safe locks - any writer needs to get a
108 * irq-safe write-lock, but readers can get non-irqsafe
109 * read-locks.
111 * Most gcc versions have a nasty bug with empty initializers.
113 #if (__GNUC__ > 2)
114 typedef struct { } rwlock_t;
115 #define RW_LOCK_UNLOCKED (rwlock_t) { }
116 #else
117 typedef struct { int gcc_is_buggy; } rwlock_t;
118 #define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
119 #endif
121 #define rwlock_init(lock) do { } while(0)
122 #define read_lock(lock) (void)(lock) /* Not "unused variable". */
123 #define read_unlock(lock) do { } while(0)
124 #define write_lock(lock) (void)(lock) /* Not "unused variable". */
125 #define write_unlock(lock) do { } while(0)
127 #endif /* !SMP */
129 /* "lock on reference count zero" */
130 #ifndef atomic_dec_and_lock
131 #include <asm/atomic.h>
132 extern int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);
133 #endif
135 #endif /* __LINUX_SPINLOCK_H */