ChibiOS/RT Logo ChibiOS/RT

Architecture - Reference Manual - Guides

Invoking multiple primitives as a single atomic operation

It is often necessary to invoke multiple operations involving a reschedule as a single atomic operation.
ChibiOS/RT already implements APIs that perform complex operations, as example the API chSemSignalWait() performs two operations atomically.
If more complex operations are required in your application then it is possible to build macro-operations, see the following example:

  chSysLock();

  chSemSignalI(&sem1);
  chSemSignalI(&sem2);
  chMtxUnlockS();
  chSchRescheduleS();

  chSysUnlock();

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.
An hypothetical chSemSignalSignalWait() operation could be implemented as follow:

  chSysLock();

  chSemSignalI(&sem1);
  chSemSignalI(&sem2);
  chSemWaitS(&Sem3);  /* May reschedule or not. */
  chSchRescheduleS(); /* This one reschedules if necessary. */

  chSysUnlock();

In general multiple I-Class and (non rescheduling) S-Class APIs can be included and the block is terminated by a rescheduling S-Class API. An extra chSchRescheduleS() can be present at the very end of the block, it only reschedules if a reschedule is still required.


Generated on Sun Jul 11 13:13:07 2010 for ChibiOS/RT by doxygen 1.6.3