Re: spinlock

Jamie Lokier (lkd@tantalophile.demon.co.uk)
Sat, 27 Nov 1999 14:16:59 +0100


wu_yb wrote:
> typedef struct {
> volatile unsigned int lock ;
> } spinlock ;
>
> why the spinlock structure should be converted to dummy_lock_t
> in inline asm code:
> typedef struct { unsigned long a[100] ; } dummy_lock_t ;
> #define dummy_lock(lock) (*(dummy_lock_t*)(lock))
>
> I see many conversion like this in kernel source, can anyone help me!!!

The asm statements you see in spin_lock and spin_unlock refer to the
lock by implication from its value, rather than by its address. As long
as GCC uses the actual memory location this is fine, and produces better
code than using the address.

The dummy_lock cast prevents GCC from "optimising" the lock by copying
it into a register and using that in the asm. It works because GCC is not
clever enough to optimise a 100-entry array in this way.

-- Jamie

-
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/