void OSSchedLock (OS_ERR *p_err)
...
File
...
Called from
...
Code enabled by
...
os_core.c
...
Task only
...
Description
OSSchedLock()
prevents prevents task rescheduling until its counterpart, OSSchedUnlock()
, is called. The task that calls calls OSSchedLock()
retains 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 and OSSchedUnlock()
must must be used in pairs.
µC/OS-III allows allows OSSchedLock()
to to be nested up to 250 levels deep. Scheduling is enabled when an equal number of of OSSchedUnlock()
calls calls have been made.
Files
os.h/os_core.c
Prototype
Code Block |
---|
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
If the user
...
attempted to nest the locking more than 250 times.
OS_ERR_OS_NOT_RUNNING
if
If the function is called before calling OSStart()
.
OS_ERR_SCHED_LOCK_ISR
if
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
Code Block | ||
---|---|---|
| ||
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" */
:
:
}
} |