<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <HTML ><HEAD ><TITLE >Locking Between User Context and BHs</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Unreliable Guide To Locking" HREF="book1.html"><LINK REL="UP" TITLE="Two Main Types of Kernel Locks: Spinlocks and Semaphores" HREF="c88.html"><LINK REL="PREVIOUS" TITLE="Locking Only In User Context" HREF="x111.html"><LINK REL="NEXT" TITLE="Locking Between User Context and Tasklets/Soft IRQs" HREF="x138.html"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Unreliable Guide To Locking</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="x111.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Two Main Types of Kernel Locks: Spinlocks and Semaphores</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="x138.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="LOCK-USER-BH" ></A >Locking Between User Context and BHs</H1 ><P > If a <A HREF="g388.html#GLOSS-BH" ><I CLASS="FIRSTTERM" >bottom half</I ></A > shares data with user context, you have two problems. Firstly, the current user context can be interrupted by a bottom half, and secondly, the critical region could be entered from another CPU. This is where <TT CLASS="FUNCTION" >spin_lock_bh()</TT > (<TT CLASS="FILENAME" >include/linux/spinlock.h</TT >) is used. It disables bottom halves on that CPU, then grabs the lock. <TT CLASS="FUNCTION" >spin_unlock_bh()</TT > does the reverse. </P ><P > This works perfectly for <A HREF="g388.html#GLOSS-UP" ><I CLASS="FIRSTTERM" ><SPAN CLASS="ACRONYM" >UP </SPAN ></I ></A > as well: the spin lock vanishes, and this macro simply becomes <TT CLASS="FUNCTION" >local_bh_disable()</TT > (<TT CLASS="FILENAME" >include/asm/softirq.h</TT >), which protects you from the bottom half being run. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="x111.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="book1.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="x138.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Locking Only In User Context</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="c88.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Locking Between User Context and Tasklets/Soft IRQs</TD ></TR ></TABLE ></DIV ></BODY ></HTML >