[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lock_kernel



On Sat, May 19, 2001 at 02:12:10AM -0700, siva prasad wrote:
> when the macro lock_kernel is defined as 
> do{ } while(0)
> and when it comes 'out' immediately('cos the condition
> is false by having specified 0) from the flow of
> control what is the rational behind using it?

It is only defined as such for non-SMP systems, because you can't have
inter-CPU locks on single CPU systems. On i386 SMP systems, lock_kernel
is an inline function:

extern __inline__ void lock_kernel(void)
{
        if (!++current->lock_depth)
                spin_lock(&kernel_flag);
}

So on a non-SMP system, the macro expands to 'do{} while(0)' and gets
optimised away.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2783635  Fax: +31-15-2781843  Email: J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/