See patch. Uwe. -- http://www.hermann-uwe.de | http://www.holsham-traders.de http://www.crazy-hacks.org | http://www.unmaintained-free-software.org
Various spinlock-related cleanups:
- Revert back to spinlock_t (instead of struct spinlock). This is fine
in this special case, as the contents of spinlock_t are not meant to
ever be accessed directly (only by "accessor" functions).
This fits fine in the coding guidelines, which say:
"In general, a pointer, or a struct that has elements that can reasonably
be directly accessed should _never_ be a typedef."
- Drop the spin_lock_string and spin_unlock_string macros, they're pretty
useless as they're only used in a single place and a macro doesn't make
this code any more readable, IMO.
- Minor coding style fixes.
Tested in QEMU only.
Signed-off-by: Uwe Hermann <[EMAIL PROTECTED]>
Index: include/arch/x86/arch/spinlock.h
===================================================================
--- include/arch/x86/arch/spinlock.h (Revision 434)
+++ include/arch/x86/arch/spinlock.h (Arbeitskopie)
@@ -10,61 +10,48 @@
* (Written by Stefan Reinauer <[EMAIL PROTECTED]> for coresystems GmbH)
*/
-#ifndef ARCH_SPINLOCK_H
-#define ARCH_SPINLOCK_H
-
/*
* Your basic SMP spinlocks, allowing only a single CPU anywhere.
*/
-struct spinlock {
+#ifndef ARCH_SPINLOCK_H
+#define ARCH_SPINLOCK_H
+
+typedef struct {
volatile unsigned int lock;
-};
+} spinlock_t;
-#define SPIN_LOCK_UNLOCKED (struct spinlock) { 1 }
+#define SPIN_LOCK_UNLOCKED (spinlock_t) { 1 }
/*
- * Simple spin lock operations. There are two variants, one clears IRQ's
- * on the local processor, one does not.
- *
+ * Simple spin lock operations.
* We make no fairness assumptions. They have a cost.
*/
-#define barrier() __asm__ __volatile__("": : :"memory")
+#define barrier() __asm__ __volatile__("" : : : "memory")
#define spin_is_locked(x) (*(volatile char *)(&(x)->lock) <= 0)
-#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x))
+#define spin_unlock_wait(x) do { barrier(); } while (spin_is_locked(x))
-#define spin_lock_string \
- "\n1:\t" \
- "lock ; decb %0\n\t" \
- "js 2f\n" \
- ".section .text.lock,\"ax\"\n" \
- "2:\t" \
- "cmpb $0,%0\n\t" \
- "rep;nop\n\t" \
- "jle 2b\n\t" \
- "jmp 1b\n" \
- ".previous"
-
-/*
- * This works. Despite all the confusion.
- */
-#define spin_unlock_string \
- "movb $1,%0"
-
-static inline __attribute__((always_inline)) void spin_lock(struct spinlock *lock)
+static inline __attribute__((always_inline)) void spin_lock(spinlock_t *lock)
{
- __asm__ __volatile__(
- spin_lock_string
- :"=m" (lock->lock) : : "memory");
+ __asm__ __volatile__("\n1:\t"
+ "lock ; decb %0\n\t"
+ "js 2f\n"
+ ".section .text.lock,\"ax\"\n"
+ "2:\t"
+ "cmpb $0,%0\n\t"
+ "rep;nop\n\t"
+ "jle 2b\n\t"
+ "jmp 1b\n"
+ ".previous"
+ :"=m" (lock->lock) : : "memory");
}
-static inline __attribute__((always_inline)) void spin_unlock(struct spinlock *lock)
+static inline __attribute__((always_inline)) void spin_unlock(spinlock_t *lock)
{
- __asm__ __volatile__(
- spin_unlock_string
- :"=m" (lock->lock) : : "memory");
+ __asm__ __volatile__("movb $1,%0"
+ :"=m" (lock->lock) : : "memory");
}
-#define spin_define(spin) static struct spinlock spin = SPIN_LOCK_UNLOCKED
+#define spin_define(spin) static spinlock_t spin = SPIN_LOCK_UNLOCKED
#endif /* ARCH_SPINLOCK_H */
Index: device/device.c
===================================================================
--- device/device.c (Revision 434)
+++ device/device.c (Arbeitskopie)
@@ -38,6 +38,9 @@
#include <lib.h>
#include <spinlock.h>
+/* Statically define a spinlock. */
+spin_define(dev_lock);
+
/** Linked list of all devices. */
struct device *all_devices = &dev_root;
@@ -183,9 +186,6 @@
* @return Pointer to the newly created device structure.
* @see device_path
*/
-
-spin_define(dev_lock);
-
struct device *alloc_dev(struct bus *parent, struct device_path *path,
struct device_id *devid)
{
signature.asc
Description: Digital signature
-- linuxbios mailing list [email protected] http://www.linuxbios.org/mailman/listinfo/linuxbios
