Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from this space and version 3.06.00

When setting OS_CFG_ISR_POST_DEFERRED_EN to 1, µC/OS-III locks the scheduler before entering a critical section and unlocks the scheduler when leaving the critical section.

OS_CRITICAL_ENTER() simply increments OSSchedLockNestingCtr to lock the scheduler. This is the variable the scheduler uses to determine whether or not the scheduler is locked. It is locked when the value is non-zero.

OS_CRITICAL_EXIT() decrements OSSchedLockNestingCtr and when the value reaches zero, invokes the scheduler.

OS_CRITICAL_EXIT_NO_SCHED() also decrements OSSchedLockNestingCtr, but does not invoke the scheduler when the value reaches zero.

The code for the macros is shown in Listing 4-2It is possible for a task to lock the scheduler and thus prevent preemption.  In other words, locking the scheduler makes the current task the highest priority task.  This is accomplished by calling OSSchedLock().  To unlock the scheduler, you simply call OSSchedUnlock().

Interrupts are still recognized when the scheduler is locked but the kernel will not switch to a higher priority task while the scheduler is locked.  It's generally not recommended to lock the scheduler in your application because it defeats the purpose of having the kernel manage your tasks.