Messages in this thread Patch in this message | | | From | Paul Rusty Russell <> | Subject | [PATCH] spinlock.h cleanup: linux/spinlock.h v2.3.16 | Date | Thu, 09 Sep 1999 14:24:08 +0930 |
| |
This introduces linux/spinlock.h, and moves all the arch-independent spinlock code there. It includes asm/spinlock.h if SMP, and each asm/spinlock.h includes linux/spinlock.h, so including either one works.
Rusty. --- linux-2.3-raw/include/linux/spinlock.h.~1~ Thu Sep 9 14:10:16 1999 +++ linux-2.3-raw/include/linux/spinlock.h Thu Sep 9 09:18:33 1999 @@ -0,0 +1,120 @@ +#ifndef __LINUX_SPINLOCK_H +#define __LINUX_SPINLOCK_H + +/* + * These are the generic versions of the spinlocks and read-write + * locks.. + */ +#define spin_lock_irqsave(lock, flags) do { local_irq_save(flags); spin_lock(lock); } while (0) +#define spin_lock_irq(lock) do { local_irq_disable(); spin_lock(lock); } while (0) +#define spin_lock_bh(lock) do { local_bh_disable(); spin_lock(lock); } while (0) + +#define read_lock_irqsave(lock, flags) do { local_irq_save(flags); read_lock(lock); } while (0) +#define read_lock_irq(lock) do { local_irq_disable(); read_lock(lock); } while (0) +#define read_lock_bh(lock) do { local_bh_disable(); read_lock(lock); } while (0) + +#define write_lock_irqsave(lock, flags) do { local_irq_save(flags); write_lock(lock); } while (0) +#define write_lock_irq(lock) do { local_irq_disable(); write_lock(lock); } while (0) +#define write_lock_bh(lock) do { local_bh_disable(); write_lock(lock); } while (0) + +#define spin_unlock_irqrestore(lock, flags) do { spin_unlock(lock); local_irq_restore(flags); } while (0) +#define spin_unlock_irq(lock) do { spin_unlock(lock); local_irq_enable(); } while (0) +#define spin_unlock_bh(lock) do { spin_unlock(lock); local_bh_enable(); } while (0) + +#define read_unlock_irqrestore(lock, flags) do { read_unlock(lock); local_irq_restore(flags); } while (0) +#define read_unlock_irq(lock) do { read_unlock(lock); local_irq_enable(); } while (0) +#define read_unlock_bh(lock) do { read_unlock(lock); local_bh_enable(); } while (0) + +#define write_unlock_irqrestore(lock, flags) do { write_unlock(lock); local_irq_restore(flags); } while (0) +#define write_unlock_irq(lock) do { write_unlock(lock); local_irq_enable(); } while (0) +#define write_unlock_bh(lock) do { write_unlock(lock); local_bh_enable(); } while (0) + +#ifdef CONFIG_SMP +#include <asm/spinlock.h> + +#else /* !SMP */ + +#define DEBUG_SPINLOCKS 0 /* 0 == no debugging, 1 == maintain lock state, 2 == full debug */ + +#if (DEBUG_SPINLOCKS < 1) + +/* + * Your basic spinlocks, allowing only a single CPU anywhere + * + * Gcc-2.7.x has a nasty bug with empty initializers. + */ +#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) + typedef struct { } spinlock_t; + #define SPIN_LOCK_UNLOCKED (spinlock_t) { } +#else + typedef struct { int gcc_is_buggy; } spinlock_t; + #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } +#endif + +#define spin_lock_init(lock) do { } while(0) +#define spin_lock(lock) (void)(lock) /* Not "unused variable". */ +#define spin_trylock(lock) (1) +#define spin_unlock_wait(lock) do { } while(0) +#define spin_unlock(lock) do { } while(0) + +#elif (DEBUG_SPINLOCKS < 2) + +typedef struct { + volatile unsigned int lock; +} spinlock_t; +#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } + +#define spin_lock_init(x) do { (x)->lock = 0; } while (0) +#define spin_trylock(lock) (!test_and_set_bit(0,(lock))) + +#define spin_lock(x) do { (x)->lock = 1; } while (0) +#define spin_unlock_wait(x) do { } while (0) +#define spin_unlock(x) do { (x)->lock = 0; } while (0) + +#else /* (DEBUG_SPINLOCKS >= 2) */ + +typedef struct { + volatile unsigned int lock; + volatile unsigned int babble; + const char *module; +} spinlock_t; +#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0, 25, __BASE_FILE__ } + +#include <linux/kernel.h> + +#define spin_lock_init(x) do { (x)->lock = 0; } while (0) +#define spin_trylock(lock) (!test_and_set_bit(0,(lock))) + +#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) +#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) +#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) + +#endif /* DEBUG_SPINLOCKS */ + +/* + * Read-write spinlocks, allowing multiple readers + * but only one writer. + * + * NOTE! it is quite common to have readers in interrupts + * but no interrupt writers. For those circumstances we + * can "mix" irq-safe locks - any writer needs to get a + * irq-safe write-lock, but readers can get non-irqsafe + * read-locks. + * + * Gcc-2.7.x has a nasty bug with empty initializers. + */ +#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) + typedef struct { } rwlock_t; + #define RW_LOCK_UNLOCKED (rwlock_t) { } +#else + typedef struct { int gcc_is_buggy; } rwlock_t; + #define RW_LOCK_UNLOCKED (rwlock_t) { 0 } +#endif + +#define read_lock(lock) (void)(lock) /* Not "unused variable". */ +#define read_unlock(lock) do { } while(0) +#define write_lock(lock) (void)(lock) /* Not "unused variable". */ +#define write_unlock(lock) do { } while(0) + +#endif /* !SMP */ +#endif /* __LINUX_SPINLOCK_H */ --- linux-2.3-raw/include/asm-alpha/spinlock.h.~1~ Tue Jul 20 05:42:47 1999 +++ linux-2.3-raw/include/asm-alpha/spinlock.h Thu Sep 9 09:24:52 1999 @@ -1,104 +1,10 @@ #ifndef _ALPHA_SPINLOCK_H #define _ALPHA_SPINLOCK_H -#include <asm/system.h> - -/* - * These are the generic versions of the spinlocks - * and read-write locks.. We should actually do a - * <linux/spinlock.h> with all of this. Oh, well. - */ -#define spin_lock_irqsave(lock, flags) \ - do { local_irq_save(flags); spin_lock(lock); } while (0) -#define spin_lock_irq(lock) \ - do { local_irq_disable(); spin_lock(lock); } while (0) -#define spin_lock_bh(lock) \ - do { local_bh_disable(); spin_lock(lock); } while (0) - -#define read_lock_irqsave(lock, flags) \ - do { local_irq_save(flags); read_lock(lock); } while (0) -#define read_lock_irq(lock) \ - do { local_irq_disable(); read_lock(lock); } while (0) -#define read_lock_bh(lock) \ - do { local_bh_disable(); read_lock(lock); } while (0) - -#define write_lock_irqsave(lock, flags) \ - do { local_irq_save(flags); write_lock(lock); } while (0) -#define write_lock_irq(lock) \ - do { local_irq_disable(); write_lock(lock); } while (0) -#define write_lock_bh(lock) \ - do { local_bh_disable(); write_lock(lock); } while (0) - -#define spin_unlock_irqrestore(lock, flags) \ - do { spin_unlock(lock); local_irq_restore(flags); } while (0) -#define spin_unlock_irq(lock) \ - do { spin_unlock(lock); local_irq_enable(); } while (0) -#define spin_unlock_bh(lock) \ - do { spin_unlock(lock); local_bh_enable(); } while (0) - -#define read_unlock_irqrestore(lock, flags) \ - do { read_unlock(lock); local_irq_restore(flags); } while (0) -#define read_unlock_irq(lock) \ - do { read_unlock(lock); local_irq_enable(); } while (0) -#define read_unlock_bh(lock) \ - do { read_unlock(lock); local_bh_enable(); } while (0) - -#define write_unlock_irqrestore(lock, flags) \ - do { write_unlock(lock); local_irq_restore(flags); } while (0) -#define write_unlock_irq(lock) \ - do { write_unlock(lock); local_irq_enable(); } while (0) -#define write_unlock_bh(lock) \ - do { write_unlock(lock); local_bh_enable(); } while (0) - -#ifndef __SMP__ - -/* - * Your basic spinlocks, allowing only a single CPU anywhere - * - * Gcc-2.7.x has a nasty bug with empty initializers. - */ -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) - typedef struct { } spinlock_t; - #define SPIN_LOCK_UNLOCKED (spinlock_t) { } -#else - typedef struct { int gcc_is_buggy; } spinlock_t; - #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } -#endif - -#define spin_lock_init(lock) ((void)(lock)) -#define spin_lock(lock) ((void)(lock)) -#define spin_trylock(lock) ((void)(lock), 1) -#define spin_unlock_wait(lock) ((void)(lock)) -#define spin_unlock(lock) ((void)(lock)) -#define spin_is_locked(lock) ((void)(lock), 0) - -/* - * Read-write spinlocks, allowing multiple readers - * but only one writer. - * - * NOTE! it is quite common to have readers in interrupts - * but no interrupt writers. For those circumstances we - * can "mix" irq-safe locks - any writer needs to get a - * irq-safe write-lock, but readers can get non-irqsafe - * read-locks. - * - * Gcc-2.7.x has a nasty bug with empty initializers. - */ -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) - typedef struct { } rwlock_t; - #define RW_LOCK_UNLOCKED (rwlock_t) { } -#else - typedef struct { int gcc_is_buggy; } rwlock_t; - #define RW_LOCK_UNLOCKED (rwlock_t) { 0 } -#endif - -#define read_lock(lock) ((void)(lock)) -#define read_unlock(lock) ((void)(lock)) -#define write_lock(lock) ((void)(lock)) -#define write_unlock(lock) ((void)(lock)) - -#else /* __SMP__ */ +#include <linux/spinlock.h> +#ifdef CONFIG_SMP +#include <asm/system.h> #include <linux/kernel.h> #include <asm/current.h> --- linux-2.3-raw/include/asm-arm/spinlock.h.~1~ Tue Jul 20 05:42:47 1999 +++ linux-2.3-raw/include/asm-arm/spinlock.h Thu Sep 9 13:02:48 1999 @@ -1,116 +1,9 @@ #ifndef __ASM_SPINLOCK_H #define __ASM_SPINLOCK_H -/* - * To be safe, we assume the only compiler that can cope with - * empty initialisers is EGCS. - */ -#if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 90)) -#define EMPTY_STRUCT struct { } -#define EMPTY_STRUCT_INIT(t) (t) { } -#else -#define EMPTY_STRUCT unsigned char -#define EMPTY_STRUCT_INIT(t) (t) 0 -#endif +#include <linux/spinlock.h> -/* - * These are the generic versions of the spinlocks - * and read-write locks.. We should actually do a - * <linux/spinlock.h> with all of this. Oh, well. - */ -#define spin_lock_irqsave(lock, flags) do { local_irq_save(flags); spin_lock(lock); } while (0) -#define spin_lock_irq(lock) do { local_irq_disable(); spin_lock(lock); } while (0) -#define spin_lock_bh(lock) do { local_bh_disable(); spin_lock(lock); } while (0) - -#define read_lock_irqsave(lock, flags) do { local_irq_save(flags); read_lock(lock); } while (0) -#define read_lock_irq(lock) do { local_irq_disable(); read_lock(lock); } while (0) -#define read_lock_bh(lock) do { local_bh_disable(); read_lock(lock); } while (0) - -#define write_lock_irqsave(lock, flags) do { local_irq_save(flags); write_lock(lock); } while (0) -#define write_lock_irq(lock) do { local_irq_disable(); write_lock(lock); } while (0) -#define write_lock_bh(lock) do { local_bh_disable(); write_lock(lock); } while (0) - -#define spin_unlock_irqrestore(lock, flags) do { spin_unlock(lock); local_irq_restore(flags); } while (0) -#define spin_unlock_irq(lock) do { spin_unlock(lock); local_irq_enable(); } while (0) -#define spin_unlock_bh(lock) do { spin_unlock(lock); local_bh_enable(); } while (0) - -#define read_unlock_irqrestore(lock, flags) do { read_unlock(lock); local_irq_restore(flags); } while (0) -#define read_unlock_irq(lock) do { read_unlock(lock); local_irq_enable(); } while (0) -#define read_unlock_bh(lock) do { read_unlock(lock); local_bh_enable(); } while (0) - -#define write_unlock_irqrestore(lock, flags) do { write_unlock(lock); local_irq_restore(flags); } while (0) -#define write_unlock_irq(lock) do { write_unlock(lock); local_irq_enable(); } while (0) -#define write_unlock_bh(lock) do { write_unlock(lock); local_bh_enable(); } while (0) - -#ifndef __SMP__ - -#define DEBUG_SPINLOCKS 0 /* 0 == no debugging, 1 == maintain lock state, 2 == full debugging */ - -#if (DEBUG_SPINLOCKS < 1) -/* - * Your basic spinlocks, allowing only a single CPU anywhere - */ -typedef EMPTY_STRUCT spinlock_t; -#define SPIN_LOCK_UNLOCKED EMPTY_STRUCT_INIT(spinlock_t) - -#define spin_lock_init(lock) do { } while(0) -#define spin_lock(lock) (void)(lock) /* Not "unused variable". */ -#define spin_trylock(lock) (1) -#define spin_unlock_wait(lock) do { } while(0) -#define spin_unlock(lock) do { } while(0) - -#elif (DEBUG_SPINLOCKS < 2) - -typedef struct { - volatile unsigned int lock; -} spinlock_t; -#define SPIN_LOCK_UNLOCKED (pinlock_t) { 0 } - -#define spin_lock_init(x) do { (x)->lock = 0; } while (0) -#define spin_lock(x) do { (x)->lock = 1; } while (0) -#define spin_trylock(lock) (!test_and_set_bit(0,(lock))) -#define spin_unlock_wait(x) do { } while (0) -#define spin_unlock(x) do { (x)->lock = 0; } while (0) - -#else /* (DEBUG_SPINLOCKS >= 2) */ - -typedef struct { - volatule unsigned int lock; - volatile unsigned int babble; - const char *module; -} spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0, 25, __BASE_FILE__ } - -#include <linux/kernel.h> - -#define spin_lock_init(x) do { (x)->lock = 0; } while (0) -#define spin_trylock(lock) (!test_and_set_bit(0,(lock))) - -#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) -#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) -#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) - -#endif - -/* - * Read-write spinlocks, allowing multiple readers - * but only one writer. - * - * NOTE! it is quite common to have readers in interrupts - * but no interrupt writers. For those circumstances we - * can "mix" irq-safe locks - any writer needs to get a - * irq-safe write-lock, but readers can get non-irqsafe - * read-locks. - */ -typedef EMPTY_STRUCT rwlock_t; -#define RW_LOCK_UNLOCKED EMPTY_STRUCT_INIT(rwlock_t) - -#define read_lock(lock) (void)(lock) /* Not "unused variable". */ -#define read_unlock(lock) do { } while(0) -#define write_lock(lock) (void)(lock) /* Not "unused variable". */ -#define write_unlock(lock) do { } while(0) - -#else +#ifdef CONFIG_SMP #error ARM architecture does not support spin locks #endif /* SMP */ #endif /* __ASM_SPINLOCK_H */ --- linux-2.3-raw/include/asm-i386/spinlock.h.~1~ Sun Sep 5 05:08:28 1999 +++ linux-2.3-raw/include/asm-i386/spinlock.h Thu Sep 9 09:22:54 1999 @@ -1,121 +1,9 @@ #ifndef __ASM_SPINLOCK_H #define __ASM_SPINLOCK_H -/* - * These are the generic versions of the spinlocks - * and read-write locks.. We should actually do a - * <linux/spinlock.h> with all of this. Oh, well. - */ -#define spin_lock_irqsave(lock, flags) do { local_irq_save(flags); spin_lock(lock); } while (0) -#define spin_lock_irq(lock) do { local_irq_disable(); spin_lock(lock); } while (0) -#define spin_lock_bh(lock) do { local_bh_disable(); spin_lock(lock); } while (0) - -#define read_lock_irqsave(lock, flags) do { local_irq_save(flags); read_lock(lock); } while (0) -#define read_lock_irq(lock) do { local_irq_disable(); read_lock(lock); } while (0) -#define read_lock_bh(lock) do { local_bh_disable(); read_lock(lock); } while (0) - -#define write_lock_irqsave(lock, flags) do { local_irq_save(flags); write_lock(lock); } while (0) -#define write_lock_irq(lock) do { local_irq_disable(); write_lock(lock); } while (0) -#define write_lock_bh(lock) do { local_bh_disable(); write_lock(lock); } while (0) - -#define spin_unlock_irqrestore(lock, flags) do { spin_unlock(lock); local_irq_restore(flags); } while (0) -#define spin_unlock_irq(lock) do { spin_unlock(lock); local_irq_enable(); } while (0) -#define spin_unlock_bh(lock) do { spin_unlock(lock); local_bh_enable(); } while (0) - -#define read_unlock_irqrestore(lock, flags) do { read_unlock(lock); local_irq_restore(flags); } while (0) -#define read_unlock_irq(lock) do { read_unlock(lock); local_irq_enable(); } while (0) -#define read_unlock_bh(lock) do { read_unlock(lock); local_bh_enable(); } while (0) - -#define write_unlock_irqrestore(lock, flags) do { write_unlock(lock); local_irq_restore(flags); } while (0) -#define write_unlock_irq(lock) do { write_unlock(lock); local_irq_enable(); } while (0) -#define write_unlock_bh(lock) do { write_unlock(lock); local_bh_enable(); } while (0) - -#ifndef __SMP__ - -#define DEBUG_SPINLOCKS 0 /* 0 == no debugging, 1 == maintain lock state, 2 == full debug */ - -#if (DEBUG_SPINLOCKS < 1) - -/* - * Your basic spinlocks, allowing only a single CPU anywhere - * - * Gcc-2.7.x has a nasty bug with empty initializers. - */ -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) - typedef struct { } spinlock_t; - #define SPIN_LOCK_UNLOCKED (spinlock_t) { } -#else - typedef struct { int gcc_is_buggy; } spinlock_t; - #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } -#endif - -#define spin_lock_init(lock) do { } while(0) -#define spin_lock(lock) (void)(lock) /* Not "unused variable". */ -#define spin_trylock(lock) (1) -#define spin_unlock_wait(lock) do { } while(0) -#define spin_unlock(lock) do { } while(0) - -#elif (DEBUG_SPINLOCKS < 2) - -typedef struct { - volatile unsigned int lock; -} spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } - -#define spin_lock_init(x) do { (x)->lock = 0; } while (0) -#define spin_trylock(lock) (!test_and_set_bit(0,(lock))) - -#define spin_lock(x) do { (x)->lock = 1; } while (0) -#define spin_unlock_wait(x) do { } while (0) -#define spin_unlock(x) do { (x)->lock = 0; } while (0) - -#else /* (DEBUG_SPINLOCKS >= 2) */ - -typedef struct { - volatile unsigned int lock; - volatile unsigned int babble; - const char *module; -} spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0, 25, __BASE_FILE__ } - -#include <linux/kernel.h> - -#define spin_lock_init(x) do { (x)->lock = 0; } while (0) -#define spin_trylock(lock) (!test_and_set_bit(0,(lock))) - -#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) -#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) -#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) - -#endif /* DEBUG_SPINLOCKS */ - -/* - * Read-write spinlocks, allowing multiple readers - * but only one writer. - * - * NOTE! it is quite common to have readers in interrupts - * but no interrupt writers. For those circumstances we - * can "mix" irq-safe locks - any writer needs to get a - * irq-safe write-lock, but readers can get non-irqsafe - * read-locks. - * - * Gcc-2.7.x has a nasty bug with empty initializers. - */ -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) - typedef struct { } rwlock_t; - #define RW_LOCK_UNLOCKED (rwlock_t) { } -#else - typedef struct { int gcc_is_buggy; } rwlock_t; - #define RW_LOCK_UNLOCKED (rwlock_t) { 0 } -#endif - -#define read_lock(lock) (void)(lock) /* Not "unused variable". */ -#define read_unlock(lock) do { } while(0) -#define write_lock(lock) (void)(lock) /* Not "unused variable". */ -#define write_unlock(lock) do { } while(0) - -#else /* __SMP__ */ +#include <linux/spinlock.h> +#ifdef CONFIG_SMP /* * Your basic spinlocks, allowing only a single CPU anywhere */ --- linux-2.3-raw/include/asm-m68k/spinlock.h.~1~ Tue Aug 10 04:57:31 1999 +++ linux-2.3-raw/include/asm-m68k/spinlock.h Thu Sep 9 13:03:31 1999 @@ -1,72 +1,8 @@ #ifndef __M68K_SPINLOCK_H #define __M68K_SPINLOCK_H +#include <linux/spinlock.h> /* * We don't do SMP on the m68k .... at least not yet. */ - -/* - * Gcc-2.7.x has a nasty bug with empty initializers. - */ -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) -typedef struct { } spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { } -#else -typedef struct { int gcc_is_buggy; } spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } -#endif - -#define spin_lock_init(lock) do { } while(0) -#define spin_lock(lock) (void)(lock) /* Not "unused variable". */ -#define spin_trylock(lock) (1) -#define spin_unlock_wait(lock) do { } while(0) -#define spin_unlock(lock) do { } while(0) -#define spin_lock_irq(lock) cli() -#define spin_unlock_irq(lock) sti() -#define spin_lock_bh(lock) local_bh_disable() -#define spin_unlock_bh(lock) local_bh_enable() - -#define spin_lock_irqsave(lock, flags) \ - do { save_flags(flags); cli(); } while (0) -#define spin_unlock_irqrestore(lock, flags) \ - restore_flags(flags) - -/* - * Read-write spinlocks, allowing multiple readers - * but only one writer. - * - * NOTE! it is quite common to have readers in interrupts - * but no interrupt writers. For those circumstances we - * can "mix" irq-safe locks - any writer needs to get a - * irq-safe write-lock, but readers can get non-irqsafe - * read-locks. - * - * Gcc-2.7.x has a nasty bug with empty initializers. - */ -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) -typedef struct { } rwlock_t; -#define RW_LOCK_UNLOCKED (rwlock_t) { } -#else -typedef struct { int gcc_is_buggy; } rwlock_t; -#define RW_LOCK_UNLOCKED (rwlock_t) { 0 } -#endif - -#define read_lock(lock) (void)(lock) /* Not "unused variable". */ -#define read_unlock(lock) do { } while(0) -#define write_lock(lock) (void)(lock) /* Not "unused variable". */ -#define write_unlock(lock) do { } while(0) -#define read_lock_irq(lock) cli() -#define read_unlock_irq(lock) sti() -#define write_lock_irq(lock) cli() -#define write_unlock_irq(lock) sti() -#define read_lock_bh(lock) local_bh_disable() -#define read_unlock_bh(lock) local_bh_enable() -#define write_lock_bh(lock) local_bh_disable() -#define write_unlock_bh(lock) local_bh_enable() - -#define read_lock_irqsave(lock, flags) save_and_cli(flags) -#define read_unlock_irqrestore(lock, flags) restore_flags(flags) -#define write_lock_irqsave(lock, flags) save_and_cli(flags) -#define write_unlock_irqrestore(lock, flags) restore_flags(flags) - #endif --- linux-2.3-raw/include/asm-mips/spinlock.h.~1~ Tue Jul 20 05:42:47 1999 +++ linux-2.3-raw/include/asm-mips/spinlock.h Thu Sep 9 14:14:15 1999 @@ -3,75 +3,9 @@ #ifndef __ASM_MIPS_SPINLOCK_H #define __ASM_MIPS_SPINLOCK_H -/* - * These are the generic versions of the spinlocks - * and read-write locks.. We should actually do a - * <linux/spinlock.h> with all of this. Oh, well. - */ -#define spin_lock_irqsave(lock, flags) do { local_irq_save(flags); spin_lock(lock); } while (0) -#define spin_lock_irq(lock) do { local_irq_disable(); spin_lock(lock); } while (0) -#define spin_lock_bh(lock) do { local_bh_disable(); spin_lock(lock); } while (0) - -#define read_lock_irqsave(lock, flags) do { local_irq_save(flags); read_lock(lock); } while (0) -#define read_lock_irq(lock) do { local_irq_disable(); read_lock(lock); } while (0) -#define read_lock_bh(lock) do { local_bh_disable(); read_lock(lock); } while (0) - -#define write_lock_irqsave(lock, flags) do { local_irq_save(flags); write_lock(lock); } while (0) -#define write_lock_irq(lock) do { local_irq_disable(); write_lock(lock); } while (0) -#define write_lock_bh(lock) do { local_bh_disable(); write_lock(lock); } while (0) - -#define spin_unlock_irqrestore(lock, flags) do { spin_unlock(lock); local_irq_restore(flags); } while (0) -#define spin_unlock_irq(lock) do { spin_unlock(lock); local_irq_enable(); } while (0) -#define spin_unlock_bh(lock) do { spin_unlock(lock); local_bh_enable(); } while (0) - -#define read_unlock_irqrestore(lock, flags) do { read_unlock(lock); local_irq_restore(flags); } while (0) -#define read_unlock_irq(lock) do { read_unlock(lock); local_irq_enable(); } while (0) -#define read_unlock_bh(lock) do { read_unlock(lock); local_bh_enable(); } while (0) - -#define write_unlock_irqrestore(lock, flags) do { write_unlock(lock); local_irq_restore(flags); } while (0) -#define write_unlock_irq(lock) do { write_unlock(lock); local_irq_enable(); } while (0) -#define write_unlock_bh(lock) do { write_unlock(lock); local_bh_enable(); } while (0) - -#ifndef __SMP__ - -/* - * Gcc-2.7.x has a nasty bug with empty initializers. - */ -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) - typedef struct { } spinlock_t; - #define SPIN_LOCK_UNLOCKED (spinlock_t) { } -#else - typedef struct { int gcc_is_buggy; } spinlock_t; - #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } -#endif - -#define spin_lock_init(lock) do { } while(0) -#define spin_lock(lock) do { } while(0) -#define spin_trylock(lock) (1) -#define spin_unlock_wait(lock) do { } while(0) -#define spin_unlock(lock) do { } while(0) - -/* - * Read-write spinlocks, allowing multiple readers - * but only one writer. - * - * NOTE! it is quite common to have readers in interrupts - * but no interrupt writers. For those circumstances we - * can "mix" irq-safe locks - any writer needs to get a - * irq-safe write-lock, but readers can get non-irqsafe - * read-locks. - */ -typedef struct { } rwlock_t; -#define RW_LOCK_UNLOCKED (rwlock_t) { } - -#define read_lock(lock) do { } while(0) -#define read_unlock(lock) do { } while(0) -#define write_lock(lock) do { } while(0) -#define write_unlock(lock) do { } while(0) - -#else +#include <linux/spinlock.h> +#ifdef CONFIG_SMP #error "Nix SMP on MIPS" - #endif /* SMP */ #endif /* __ASM_MIPS_SPINLOCK_H */ --- linux-2.3-raw/include/asm-ppc/spinlock.h.~1~ Sat Sep 4 15:29:36 1999 +++ linux-2.3-raw/include/asm-ppc/spinlock.h Thu Sep 9 13:04:29 1999 @@ -1,79 +1,9 @@ #ifndef __ASM_SPINLOCK_H #define __ASM_SPINLOCK_H -#ifndef __SMP__ -/* - * Your basic spinlocks, allowing only a single CPU anywhere - * - * Gcc-2.7.x has a nasty bug with empty initializers. - */ -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) - typedef struct { } spinlock_t; - #define SPIN_LOCK_UNLOCKED (spinlock_t) { } -#else - typedef struct { int gcc_is_buggy; } spinlock_t; - #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } -#endif - -#define spin_lock_init(lock) do { } while(0) -#define spin_lock(lock) (void)(lock) /* Avoid warnings about unused variable */ -#define spin_trylock(lock) (1) -#define spin_unlock_wait(lock) do { } while(0) -#define spin_unlock(lock) do { } while(0) -#define spin_lock_irq(lock) cli() -#define spin_unlock_irq(lock) sti() -#define spin_lock_bh(lock) local_bh_disable() -#define spin_unlock_bh(lock) local_bh_enable() -#define spin_lock_irqsave(lock, flags) \ - do { save_flags(flags); cli(); } while (0) - -#define spin_unlock_irqrestore(lock, flags) \ - restore_flags(flags) - -/* - * Read-write spinlocks, allowing multiple readers - * but only one writer. - * - * NOTE! it is quite common to have readers in interrupts - * but no interrupt writers. For those circumstances we - * can "mix" irq-safe locks - any writer needs to get a - * irq-safe write-lock, but readers can get non-irqsafe - * read-locks. - * - * Gcc-2.7.x has a nasty bug with empty initializers. - */ -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) - typedef struct { } rwlock_t; - #define RW_LOCK_UNLOCKED (rwlock_t) { } -#else - typedef struct { int gcc_is_buggy; } rwlock_t; - #define RW_LOCK_UNLOCKED (rwlock_t) { 0 } -#endif - -#define read_lock(lock) (void)(lock) /* Avoid warnings about unused variable */ -#define read_unlock(lock) do { } while(0) -#define write_lock(lock) (void)(lock) /* Likewise */ -#define write_unlock(lock) do { } while(0) -#define read_lock_irq(lock) cli() -#define read_unlock_irq(lock) sti() -#define write_lock_irq(lock) cli() -#define write_unlock_irq(lock) sti() -#define read_lock_bh(lock) local_bh_disable() -#define read_unlock_bh(lock) local_bh_enable() -#define write_lock_bh(lock) local_bh_disable() -#define write_unlock_bh(lock) local_bh_enable() - -#define read_lock_irqsave(lock, flags) \ - do { save_flags(flags); cli(); } while (0) -#define read_unlock_irqrestore(lock, flags) \ - restore_flags(flags) -#define write_lock_irqsave(lock, flags) \ - do { save_flags(flags); cli(); } while (0) -#define write_unlock_irqrestore(lock, flags) \ - restore_flags(flags) - -#else /* __SMP__ */ +#include <linux/spinlock.h> +#ifdef CONFIG_SMP /* Simple spin lock operations. There are two variants, one clears IRQ's * on the local processor, one does not. * --- linux-2.3-raw/include/asm-sh/spinlock.h.~1~ Sat Sep 4 15:29:36 1999 +++ linux-2.3-raw/include/asm-sh/spinlock.h Thu Sep 9 14:13:54 1999 @@ -1,108 +1,9 @@ #ifndef __ASM_SH_SPINLOCK_H #define __ASM_SH_SPINLOCK_H -/* - * These are the generic versions of the spinlocks - * and read-write locks.. We should actually do a - * <linux/spinlock.h> with all of this. Oh, well. - */ -#define spin_lock_irqsave(lock, flags) do { local_irq_save(flags); spin_lock(lock); } while (0) -#define spin_lock_irq(lock) do { local_irq_disable(); spin_lock(lock); } while (0) -#define spin_lock_bh(lock) do { local_bh_disable(); spin_lock(lock); } while (0) - -#define read_lock_irqsave(lock, flags) do { local_irq_save(flags); read_lock(lock); } while (0) -#define read_lock_irq(lock) do { local_irq_disable(); read_lock(lock); } while (0) -#define read_lock_bh(lock) do { local_bh_disable(); read_lock(lock); } while (0) - -#define write_lock_irqsave(lock, flags) do { local_irq_save(flags); write_lock(lock); } while (0) -#define write_lock_irq(lock) do { local_irq_disable(); write_lock(lock); } while (0) -#define write_lock_bh(lock) do { local_bh_disable(); write_lock(lock); } while (0) - -#define spin_unlock_irqrestore(lock, flags) do { spin_unlock(lock); local_irq_restore(flags); } while (0) -#define spin_unlock_irq(lock) do { spin_unlock(lock); local_irq_enable(); } while (0) -#define spin_unlock_bh(lock) do { spin_unlock(lock); local_bh_enable(); } while (0) - -#define read_unlock_irqrestore(lock, flags) do { read_unlock(lock); local_irq_restore(flags); } while (0) -#define read_unlock_irq(lock) do { read_unlock(lock); local_irq_enable(); } while (0) -#define read_unlock_bh(lock) do { read_unlock(lock); local_bh_enable(); } while (0) - -#define write_unlock_irqrestore(lock, flags) do { write_unlock(lock); local_irq_restore(flags); } while (0) -#define write_unlock_irq(lock) do { write_unlock(lock); local_irq_enable(); } while (0) -#define write_unlock_bh(lock) do { write_unlock(lock); local_bh_enable(); } while (0) - -#ifndef __SMP__ - -#define DEBUG_SPINLOCKS 0 /* 0 == no debugging, 1 == maintain lock state, 2 == full debug */ - -#if (DEBUG_SPINLOCKS < 1) - -/* - * Your basic spinlocks, allowing only a single CPU anywhere - */ -typedef struct { } spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { } - -#define spin_lock_init(lock) do { } while(0) -#define spin_lock(lock) (void)(lock) /* Not "unused variable". */ -#define spin_trylock(lock) (1) -#define spin_unlock_wait(lock) do { } while(0) -#define spin_unlock(lock) do { } while(0) - -#elif (DEBUG_SPINLOCKS < 2) - -typedef struct { - volatile unsigned int lock; -} spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } - -#define spin_lock_init(x) do { (x)->lock = 0; } while (0) -#define spin_trylock(lock) (!test_and_set_bit(0,(lock))) - -#define spin_lock(x) do { (x)->lock = 1; } while (0) -#define spin_unlock_wait(x) do { } while (0) -#define spin_unlock(x) do { (x)->lock = 0; } while (0) - -#else /* (DEBUG_SPINLOCKS >= 2) */ - -typedef struct { - volatile unsigned int lock; - volatile unsigned int babble; - const char *module; -} spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0, 25, __BASE_FILE__ } - -#include <linux/kernel.h> - -#define spin_lock_init(x) do { (x)->lock = 0; } while (0) -#define spin_trylock(lock) (!test_and_set_bit(0,(lock))) - -#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) -#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) -#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) - -#endif /* DEBUG_SPINLOCKS */ - -/* - * Read-write spinlocks, allowing multiple readers - * but only one writer. - * - * NOTE! it is quite common to have readers in interrupts - * but no interrupt writers. For those circumstances we - * can "mix" irq-safe locks - any writer needs to get a - * irq-safe write-lock, but readers can get non-irqsafe - * read-locks. - */ -typedef struct { } rwlock_t; -#define RW_LOCK_UNLOCKED (rwlock_t) { } - -#define read_lock(lock) (void)(lock) /* Not "unused variable". */ -#define read_unlock(lock) do { } while(0) -#define write_lock(lock) (void)(lock) /* Not "unused variable". */ -#define write_unlock(lock) do { } while(0) - -#else +#include <linux/spinlock.h> +#ifdef CONFIG_SMP #error "No SMP on SH" - #endif /* SMP */ #endif /* __ASM_SH_SPINLOCK_H */ --- linux-2.3-raw/include/asm-sparc/spinlock.h.~1~ Sat Sep 4 15:29:38 1999 +++ linux-2.3-raw/include/asm-sparc/spinlock.h Thu Sep 9 13:24:04 1999 @@ -10,57 +10,7 @@ #ifndef __ASSEMBLY__ -#ifndef __SMP__ - -typedef unsigned char spinlock_t; -#define SPIN_LOCK_UNLOCKED 0 - -#define spin_lock_init(lock) do { } while(0) -#define spin_lock(lock) do { } while(0) -#define spin_trylock(lock) (1) -#define spin_unlock_wait(lock) do { } while(0) -#define spin_unlock(lock) do { } while(0) -#define spin_lock_irq(lock) cli() -#define spin_unlock_irq(lock) sti() -#define spin_lock_bh(lock) local_bh_disable() -#define spin_unlock_bh(lock) local_bh_enable() - -#define spin_lock_irqsave(lock, flags) save_and_cli(flags) -#define spin_unlock_irqrestore(lock, flags) restore_flags(flags) - -/* - * Read-write spinlocks, allowing multiple readers - * but only one writer. - * - * NOTE! it is quite common to have readers in interrupts - * but no interrupt writers. For those circumstances we - * can "mix" irq-safe locks - any writer needs to get a - * irq-safe write-lock, but readers can get non-irqsafe - * read-locks. - */ -typedef struct { volatile unsigned int lock; } rwlock_t; -#define RW_LOCK_UNLOCKED (rwlock_t) { 0 } - -#define read_lock(lock) do { } while(0) -#define read_unlock(lock) do { } while(0) -#define write_lock(lock) do { } while(0) -#define write_unlock(lock) do { } while(0) -#define read_lock_irq(lock) cli() -#define read_unlock_irq(lock) sti() -#define write_lock_irq(lock) cli() -#define write_unlock_irq(lock) sti() -#define read_lock_bh(lock) local_bh_disable() -#define read_unlock_bh(lock) local_bh_enable() -#define write_lock_bh(lock) local_bh_disable() -#define write_unlock_bh(lock) local_bh_enable() - -#define read_lock_irqsave(lock, flags) save_and_cli(flags) -#define read_unlock_irqrestore(lock, flags) restore_flags(flags) -#define write_lock_irqsave(lock, flags) save_and_cli(flags) -#define write_unlock_irqrestore(lock, flags) restore_flags(flags) - -#else /* !(__SMP__) */ - +#ifdef CONFIG_SMP #include <asm/psr.h> /* Define this to use the verbose/debugging versions in arch/sparc/lib/debuglocks.c */ --- linux-2.3-raw/include/asm-sparc64/spinlock.h.~1~ Sat Sep 4 15:29:39 1999 +++ linux-2.3-raw/include/asm-sparc64/spinlock.h Thu Sep 9 14:07:22 1999 @@ -8,88 +8,7 @@ #ifndef __ASSEMBLY__ -#ifndef __SMP__ - -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) - typedef struct { } spinlock_t; -# define SPIN_LOCK_UNLOCKED (spinlock_t) { } -#else - typedef unsigned char spinlock_t; -# define SPIN_LOCK_UNLOCKED 0 -#endif - -#define spin_lock_init(lock) do { } while(0) -#define spin_lock(lock) (void)(lock) /* Avoid warnings about unused variable */ -#define spin_trylock(lock) (1) -#define spin_unlock_wait(lock) do { } while(0) -#define spin_unlock(lock) do { } while(0) -#define spin_lock_irq(lock) cli() -#define spin_unlock_irq(lock) sti() -#define spin_lock_bh(lock) \ -do { local_bh_count++; \ - barrier(); \ -} while(0) -#define spin_unlock_bh(lock) \ -do { barrier(); \ - local_bh_count--; \ -} while(0) - -#define spin_lock_irqsave(lock, flags) save_and_cli(flags) -#define spin_unlock_irqrestore(lock, flags) restore_flags(flags) - -/* - * Read-write spinlocks, allowing multiple readers - * but only one writer. - * - * NOTE! it is quite common to have readers in interrupts - * but no interrupt writers. For those circumstances we - * can "mix" irq-safe locks - any writer needs to get a - * irq-safe write-lock, but readers can get non-irqsafe - * read-locks. - */ -#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) - typedef struct { } rwlock_t; -# define RW_LOCK_UNLOCKED (rwlock_t) { } -#else - typedef unsigned int rwlock_t; -# define RW_LOCK_UNLOCKED (rwlock_t) { 0 } -#endif - -#define read_lock(lock) (void)(lock) /* Avoid warnings about unused variable */ -#define read_unlock(lock) do { } while(0) -#define write_lock(lock) (void)(lock) /* Likewise */ -#define write_unlock(lock) do { } while(0) -#define read_lock_irq(lock) cli() -#define read_unlock_irq(lock) sti() -#define read_lock_bh(lock) \ -do { local_bh_count++; \ - barrier(); \ -} while(0) -#define read_unlock_bh(lock) \ -do { barrier(); \ - local_bh_count--; \ -} while(0) - -#define write_lock_irq(lock) cli() -#define write_unlock_irq(lock) sti() - -#define write_lock_bh(lock) \ -do { local_bh_count++; \ - barrier(); \ -} while(0) - -#define write_unlock_bh(lock) \ -do { barrier(); \ - local_bh_count--; \ -} while(0) - -#define read_lock_irqsave(lock, flags) save_and_cli(flags) -#define read_unlock_irqrestore(lock, flags) restore_flags(flags) -#define write_lock_irqsave(lock, flags) save_and_cli(flags) -#define write_unlock_irqrestore(lock, flags) restore_flags(flags) - -#else /* !(__SMP__) */ - +#ifdef CONFIG_SMP /* To get debugging spinlocks which detect and catch * deadlock situations, set DEBUG_SPINLOCKS in the sparc64 * specific makefile and rebuild your kernel. -- Hacking time.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |