43 lines
1.4 KiB
Plaintext
43 lines
1.4 KiB
Plaintext
/**
|
|
* @page article_atomic Invoking multiple primitives as a single atomic operation
|
|
* @{
|
|
* It is often necessary to invoke multiple operations involving a
|
|
* reschedulation as a single atomic operation.<br>
|
|
* ChibiOS/RT already implements APIs that perform complex operations, as
|
|
* example the API @p chSemSignalWait() 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:
|
|
* @code
|
|
chSysLock();
|
|
|
|
chSemSignalI(&sem1);
|
|
chSemSignalI(&sem2);
|
|
if (tp != NULL) {
|
|
chThdResumeI(tp);
|
|
tp = NULL;
|
|
}
|
|
chSchRescheduleS();
|
|
|
|
chSysUnlock();
|
|
* @endcode
|
|
* The above example performs a signal operation on two semaphores, optionally
|
|
* resumes a thread, and performs a final reschedulation. The three operations
|
|
* are performed atomically.<br>
|
|
* An hypotetical @p chSemSignalSignalWait() operation could be implemented as
|
|
* follow:
|
|
* @code
|
|
chSysLock();
|
|
|
|
chSemSignalI(&sem1);
|
|
chSemSignalI(&sem2);
|
|
chSemWaitS(&Sem3);
|
|
chSchRescheduleS(); /* Because chSemWaitS() might not reschedule internally.*/
|
|
|
|
chSysUnlock();
|
|
* @endcode
|
|
* In general multiple I-Class APIs can be included and the block is terminated
|
|
* by an S-Class API that performs a reschedulation. Optionally a
|
|
* @p chSchRescheduleS() is present at the very end of the block.
|
|
*/
|
|
/** @} */
|