1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>__test_and_clear_bit</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="The Linux Kernel API"><link rel="up" href="ch02s03.html" title="Bit Operations"><link rel="prev" href="API-test-and-clear-bit.html" title="test_and_clear_bit"><link rel="next" href="API-test-and-change-bit.html" title="test_and_change_bit"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">__test_and_clear_bit</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-test-and-clear-bit.html">Prev</a> </td><th width="60%" align="center">Bit Operations</th><td width="20%" align="right"> <a accesskey="n" href="API-test-and-change-bit.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API---test-and-clear-bit"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>__test_and_clear_bit — 2 Clear a bit and return its old value 3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">__test_and_clear_bit </b>(</code></td><td>long <var class="pdparam">nr</var>, </td></tr><tr><td> </td><td>volatile unsigned long * <var class="pdparam">addr</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idp1123158580"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>nr</code></em></span></dt><dd><p> 4 Bit to clear 5 </p></dd><dt><span class="term"><em class="parameter"><code>addr</code></em></span></dt><dd><p> 6 Address to count from 7 </p></dd></dl></div></div><div class="refsect1"><a name="idp1123161100"></a><h2>Description</h2><p> 8 This operation is non-atomic and can be reordered. 9 If two examples of this operation race, one can appear to succeed 10 but actually fail. You must protect multiple accesses with a lock. 11</p></div><div class="refsect1"><a name="idp1123161876"></a><h2>Note</h2><p> 12 the operation is performed atomically with respect to 13 the local CPU, but not other CPUs. Portable code should not 14 rely on this behaviour. 15 KVM relies on this behaviour on x86 for modifying memory that is also 16</p></div><div class="refsect1"><a name="idp1123162684"></a><h2>accessed from a hypervisor on the same CPU if running in a VM</h2><p> 17 don't change 18 this without also updating arch/x86/kernel/kvm.c 19</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-test-and-clear-bit.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02s03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-test-and-change-bit.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">test_and_clear_bit</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">test_and_change_bit</span></td></tr></table></div></body></html> 20