lkml.org 
[lkml]   [1999]   [Nov]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: spinlock
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/

\
 
 \ /
  Last update: 2005-03-22 13:55    [W:0.479 / U:0.180 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site