📄 work_queues.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head> <title></title> <link rel="stylesheet" media="screen" type="text/css" href="./style.css" /> <link rel="stylesheet" media="screen" type="text/css" href="./design.css" /> <link rel="stylesheet" media="print" type="text/css" href="./print.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><a href=start.html>start</a></br><h4><a name="work_queues" id="work_queues">Work Queues</a></h4><div class="level4"><p> A Work Queue is a method used to allow a non blockable process like an interrupt service routine to trigger a deferred process that may include blocking functions.</p><p>There is a default work queue monitored by the kernel event deamon keventd. It is possible to create your own work queues </p><p>The following example shows how to use a (possibly) blocking call like vfree to delete a structure.</p><p>An example of using a work queue </p><pre class="code c"> <span class="co2">#include <linux/workqueue.h> </span> <span class="kw4">struct</span> work_struct work; INIT_WORK<span class="br0">(</span>&work, delete_my_item, <span class="br0">(</span><span class="kw4">void</span> *<span class="br0">)</span>item <span class="br0">)</span> schedule_work<span class="br0">(</span>&work<span class="br0">)</span>; ... <span class="kw4">void</span> delete_my_item<span class="br0">(</span> <span class="kw4">void</span> * item<span class="br0">)</span> <span class="br0">{</span> vfree<span class="br0">(</span>item<span class="br0">)</span>; <span class="br0">}</span></pre><p>This is an example of creating a work queue</p><pre class="code c"> <span class="kw4">struct</span> workqueue_struct * keventd_wq; <span class="kw4">void</span> init_workqueues<span class="br0">(</span><span class="kw4">void</span><span class="br0">)</span><span class="br0">{</span> keventd_wq = create_workqueue<span class="br0">(</span><span class="st0">"events"</span><span class="br0">)</span>; BUG_ON<span class="br0">(</span>!keventd_wq<span class="br0">)</span>;<span class="br0">}</span> </pre><p>The Kernel Functions for the Work Queue system are as follows </p><table class="inline"> <tr> <td> schedule_work </td><td>queue the work on the keventd work queue</td> </tr> <tr> <td> schedule_delayed_work </td><td> queue the work on the keventd after a delay in jiffies</td> </tr> <tr> <td> schedule_delayed_work_on </td><td> queue the work on a selected cpu</td> </tr> <tr> <td class="leftalign"> flush_scheduled_work </td><td> wait until all schedule jobs are completed</td> </tr> <tr> <td class="leftalign"> queue_work </td><td class="leftalign"> queue the task on a work queue </td> </tr> <tr> <td> queue_delayed_work </td><td> queue the work after a delay in jiffies</td> </tr> <tr> <td> flush_workqueue </td><td> wait until all the queued tasks have completed</td> </tr> <tr> <td> __create_workqueue </td><td> create a new workqueue</td> </tr> <tr> <td> destroy_workqueue </td><td> delete a workqueue</td> </tr></table><br /></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -