gnuk/ChibiOS_2.0.6/docs/html/article_atomic.html

68 lines
5.3 KiB
HTML
Raw Normal View History

2010-08-10 03:11:02 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>ChibiOS/RT: Invoking multiple primitives as a single atomic operation</title>
<link href="custom.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<table style="text-align: center; width: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 80px;"><img alt="ChibiOS/RT Logo" src="logo_small.png"></td>
<td><big><big>ChibiOS/RT</big></big><br><br>Architecture - Reference Manual - Guides</td>
<td style="width: 80px;"></td>
</tr>
</tbody>
</table>
<hr size="1">
2010-11-22 05:53:37 +00:00
<!-- Generated by Doxygen 1.7.1 -->
2010-08-10 03:11:02 +00:00
<div class="navigation" id="top">
<div class="tabs">
2010-11-22 05:53:37 +00:00
<ul class="tablist">
2010-08-10 03:11:02 +00:00
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
2010-11-22 05:53:37 +00:00
<div class="navpath">
<ul>
<li><a class="el" href="main.html">ChibiOS/RT</a> </li>
<li><a class="el" href="articles.html">Articles and Code Samples</a> </li>
<li><a class="el" href="page_kb.html">Knowledge Base</a> </li>
</ul>
2010-08-10 03:11:02 +00:00
</div>
</div>
2010-11-22 05:53:37 +00:00
<div class="header">
<div class="headertitle">
<h1>Invoking multiple primitives as a single atomic operation </h1> </div>
</div>
2010-08-10 03:11:02 +00:00
<div class="contents">
2010-11-22 05:53:37 +00:00
<p>It is often necessary to invoke multiple operations involving a reschedule as a single atomic operation.<br/>
2010-08-10 03:11:02 +00:00
ChibiOS/RT already implements APIs that perform complex operations, as example the API <code><a class="el" href="group__semaphores.html#ga0dc7b4339506de346d67b4560b271e44" title="Performs atomic signal and wait operations on two semaphores.">chSemSignalWait()</a></code> performs two operations atomically.<br/>
If more complex operations are required in your application then it is possible to build macro-operations, see the following example: </p>
<div class="fragment"><pre class="fragment"> <a class="code" href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42" title="Enters the kernel lock mode.">chSysLock</a>();
<a class="code" href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d" title="Performs a signal operation on a semaphore.">chSemSignalI</a>(&amp;sem1);
<a class="code" href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d" title="Performs a signal operation on a semaphore.">chSemSignalI</a>(&amp;sem2);
<a class="code" href="group__mutexes.html#ga705fa60fb8aa28a6632f693e83f78c96" title="Unlocks the next owned mutex in reverse lock order.">chMtxUnlockS</a>();
<a class="code" href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20" title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>();
<a class="code" href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e" title="Leaves the kernel lock mode.">chSysUnlock</a>();
</pre></div><p> The above example performs a signal operation on two semaphores, unlocks the last acquired mutex and finally performs a reschedule. All the operations are performed atomically.<br/>
An hypothetical <code>chSemSignalSignalWait()</code> operation could be implemented as follow: </p>
<div class="fragment"><pre class="fragment"> <a class="code" href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42" title="Enters the kernel lock mode.">chSysLock</a>();
<a class="code" href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d" title="Performs a signal operation on a semaphore.">chSemSignalI</a>(&amp;sem1);
<a class="code" href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d" title="Performs a signal operation on a semaphore.">chSemSignalI</a>(&amp;sem2);
<a class="code" href="group__semaphores.html#gaa2c0367078533e291d2e889e251d8b67" title="Performs a wait operation on a semaphore.">chSemWaitS</a>(&amp;Sem3); <span class="comment">/* May reschedule or not. */</span>
<a class="code" href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20" title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>(); <span class="comment">/* This one reschedules if necessary. */</span>
<a class="code" href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e" title="Leaves the kernel lock mode.">chSysUnlock</a>();
</pre></div><p> In general multiple <a class="el" href="concepts.html#I-Class">I-Class</a> and (non rescheduling) <a class="el" href="concepts.html#S-Class">S-Class</a> APIs can be included and the block is terminated by a rescheduling <a class="el" href="concepts.html#S-Class">S-Class</a> API. An extra <code><a class="el" href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20" title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS()</a></code> can be present at the very end of the block, it only reschedules if a reschedule is still required. </p>
</div>
<hr size="1"><address style="text-align: right;"><small>
2010-11-22 05:53:37 +00:00
Generated on Sun Oct 24 2010 09:40:43 for ChibiOS/RT by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.7.1</small></address>
2010-08-10 03:11:02 +00:00
</body>
</html>