<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>Queuing</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel" /><link rel="up" href="ch07.html" title="Chapter 7. Wait Queues include/linux/wait.h" /><link rel="prev" href="ch07.html" title="Chapter 7. Wait Queues include/linux/wait.h" /><link rel="next" href="ch07s03.html" title="Waking Up Queued Tasks" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Queuing</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch07.html">Prev</a> </td><th width="60%" align="center">Chapter 7. Wait Queues <code class="filename">include/linux/wait.h</code> </th><td width="20%" align="right"> <a accesskey="n" href="ch07s03.html">Next</a></td></tr></table><hr /></div><div class="sect1" title="Queuing"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="queue-waitqueue"></a>Queuing</h2></div></div></div><p> Placing yourself in the waitqueue is fairly complex, because you must put yourself in the queue before checking the condition. There is a macro to do this: <code class="function">wait_event_interruptible()</code> <code class="filename">include/linux/wait.h</code> The first argument is the wait queue head, and the second is an expression which is evaluated; the macro returns <span class="returnvalue">0</span> when this expression is true, or <span class="returnvalue">-ERESTARTSYS</span> if a signal is received. The <code class="function">wait_event()</code> version ignores signals. </p><p> Do not use the <code class="function">sleep_on()</code> function family - it is very easy to accidentally introduce races; almost certainly one of the <code class="function">wait_event()</code> family will do, or a loop around <code class="function">schedule_timeout()</code>. If you choose to loop around <code class="function">schedule_timeout()</code> remember you must set the task state (with <code class="function">set_current_state()</code>) on each iteration to avoid busy-looping. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch07.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch07.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch07s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 7. Wait Queues <code class="filename">include/linux/wait.h</code>  </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Waking Up Queued Tasks</td></tr></table></div></body></html>