OSSchedLock
Description
OSSchedLock() prevents task rescheduling until its counterpart, OSSchedUnlock(), is called. The task that calls OSSchedLock() retains control of the CPU, even though other higher- priority tasks are ready-to-run. However, interrupts are still recognized and serviced (assuming interrupts are enabled). OSSchedLock() and OSSchedUnlock() must be used in pairs.
µC/OS-III allows OSSchedLock() to be nested up to 250 levels deep. Scheduling is enabled when an equal number of OSSchedUnlock() calls have been made.
Files
os.h/os_core.c
Prototype
void OSSchedLock (OS_ERR *p_err)Arguments
p_err
is a pointer to a variable that will contain an error code returned by this function.
OS_ERR_NONE
If the scheduler is locked.
OS_ERR_LOCK_NESTING_OVF
If the user attempted to nest the locking more than 250 times.
OS_ERR_OS_NOT_RUNNING
If the function is called before calling OSStart().
OS_ERR_SCHED_LOCK_ISR
If OS_CFG_CALLED_FROM_ISR_CHK_EN set to DEF_ENABLED in os_cfg.h: if you attempted to call OSSchedLock() from an ISR.
Returned Value
None
Required Configuration
None
Callers
Application.
Notes/Warnings
After calling
OSSchedLock(), the application must not make system calls that suspend execution of the current task; that is, the application cannot callOSTimeDly(),OSTimeDlyHMSM(),OSFlagPend(),OSSemPend(),OSMutexPend(), orOSQPend(). Since the scheduler is locked out, no other task is allowed to run, and the system will lock up.
Example Usage
OSSchedLock() example usage
void TaskX (void *p_arg)
{
OS_ERR err;
(void)&p_arg;
while (DEF_ON) {
:
OSSchedLock(&err); /* Prevent other tasks to run */
/* Check "err" */
:
: /* Code protected from context switch */
:
OSSchedUnlock(&err); /* Enable other tasks to run */
/* Check "err" */
:
:
}
}