ChibiOS/RT already implements APIs that perform complex operations, as example the API <code><aclass="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>
<divclass="fragment"><preclass="fragment"><aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aclass="code"href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d"title="Performs a signal operation on a semaphore.">chSemSignalI</a>(&sem1);
<aclass="code"href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d"title="Performs a signal operation on a semaphore.">chSemSignalI</a>(&sem2);
<aclass="code"href="group__mutexes.html#ga705fa60fb8aa28a6632f693e83f78c96"title="Unlocks the next owned mutex in reverse lock order.">chMtxUnlockS</a>();
<aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>();
<aclass="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>
<divclass="fragment"><preclass="fragment"><aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aclass="code"href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d"title="Performs a signal operation on a semaphore.">chSemSignalI</a>(&sem1);
<aclass="code"href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d"title="Performs a signal operation on a semaphore.">chSemSignalI</a>(&sem2);
<aclass="code"href="group__semaphores.html#gaa2c0367078533e291d2e889e251d8b67"title="Performs a wait operation on a semaphore.">chSemWaitS</a>(&Sem3); <spanclass="comment">/* May reschedule or not. */</span>
<aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>(); <spanclass="comment">/* This one reschedules if necessary. */</span>
<aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
</pre></div><p> In general multiple <aclass="el"href="concepts.html#I-Class">I-Class</a> and (non rescheduling) <aclass="el"href="concepts.html#S-Class">S-Class</a> APIs can be included and the block is terminated by a rescheduling <aclass="el"href="concepts.html#S-Class">S-Class</a> API. An extra <code><aclass="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>
Generated on Sun Nov 28 2010 14:09:53 for ChibiOS/RT by <ahref="http://www.doxygen.org/index.html"><imgsrc="doxygen.png"alt="doxygen"align="middle"border="0"></a> 1.7.1</small></address>