Home > other >  Why say ucos ii in dynamic change task priority takes a long time
Why say ucos ii in dynamic change task priority takes a long time

Time:10-24

Ucos ii, call OSTaskChangePrio () function to dynamically change the priority tasks, why a lot of people say it takes a long time? Saw this function, it maybe two or three and ten instructions, calculate by 20 ns machine cycle, that its execution time is no more than 1 us, this time is long?


The attached OSTaskChangePrio () function:
INT8U OSTaskChangePrio (INT8U oldprio, INT8U newprio)
{
OS_TCB * PTCB;
Pevent OS_EVENT *;
INT8U x;
INT8U y;
INT8U bitx;
INT8U bity;

If ((oldprio & gt;=OS_LOWEST_PRIO & amp; & Oldprio!=OS_PRIO_SELF) | |//(1)
Newprio & gt;={OS_LOWEST_PRIO)
Return (OS_PRIO_INVALID);
}
OS_ENTER_CRITICAL ();
If (OSTCBPrioTbl [newprio]!=0) (OS_TCB *) {//(2)
OS_EXIT_CRITICAL ();
Return (OS_PRIO_EXIST);
} else {
OSTCBPrioTbl [newprio]=(OS_TCB *) 1;//(3)
OS_EXIT_CRITICAL ();
Y=newprio & gt;> 3;//(4)
Bity=OSMapTbl [y];
X=newprio & amp; 0 x07;
Bitx=OSMapTbl [x];
OS_ENTER_CRITICAL ();
If (oldprio==OS_PRIO_SELF) {//(5)
Oldprio=OSTCBCur - & gt; OSTCBPrio;
}
If ((PTCB=OSTCBPrioTbl [oldprio])!=0) (OS_TCB *) {//(6)
OSTCBPrioTbl [oldprio]=0 (OS_TCB *);//(7)
If (OSRdyTbl [PTCB - & gt; OSTCBY] & amp; PTCB - & gt; OSTCBBitX) {//(8)
If ((OSRdyTbl [PTCB - & gt; OSTCBY] & amp;=~ PTCB - & gt; OSTCBBitX) {//==0) (9)
OSRdyGrp & amp;=~ PTCB - & gt; OSTCBBitY;
}
OSRdyGrp |=bity;//(10)
OSRdyTbl [y] |=bitx;
} else {
If ((pevent=PTCB - & gt; OSTCBEventPtr)! (OS_EVENT *)=0) {//(11)
If ((pevent - & gt; OSEventTbl [PTCB - & gt; OSTCBY] & amp;=
~ PTCB - & gt; OSTCBBitX)==0) {
Pevent - & gt; OSEventGrp & amp;=~ PTCB - & gt; OSTCBBitY;
}
Pevent - & gt; OSEventGrp |=bity;//(12)
Pevent - & gt; OSEventTbl [y] |=bitx;
}
}
OSTCBPrioTbl [newprio]=PTCB;//(13)
PTCB - & gt; OSTCBPrio=newprio;//(14)
PTCB - & gt; OSTCBY=y;//(15)
PTCB - & gt; OSTCBX=x;
PTCB - & gt; OSTCBBitY=bity;
PTCB - & gt; OSTCBBitX=bitx;
OS_EXIT_CRITICAL ();
OSSched ();//(16)
Return (OS_NO_ERR);
} else {
OSTCBPrioTbl [newprio]=0 (OS_TCB *);//(17)
OS_EXIT_CRITICAL ();
Return (OS_PRIO_ERR);
}
}
}
  • Related