Sleep Task
ER tslp_tsk(TMO tmout)
{
Sanity check of context and arguments
if (interrupt context or dispatch disabled state or Timer or overrun
handlers)
return E_CTX;
Take Task ID of current running task
Take TCB
Enter critical section
Take number of pending wakeups
if (No pending wakeup) {
if (Not polling) {
if (timeout is NOT FOREVER) {
add taks to timer queue;
make tcb status as SLEEP with TIMEOUT
} else /* forever timeout */
make tcb status just as SLEEP
}
remove task from Ready queue and dispatch
/* critical section is exit inside dispatch */
return error code from dispatch;
}
/* else, Polling */ {
Exit critical section and return E_TMOUT; /* ?? Not needed */
/* No polling service call is provided for slp_tsk- ITRON spec */
}
/* else, pending wakeups */
Decrement the number of pending wake-ups by 1
Exit critical section and return E_OK;
}
Wakeup Task
ER wup_tsk(ID tskid)
{
if (tskid is TSK_SELF)
Take taskid from Ready Queue[0]
if (Task ID is greater than maximum of Task ID)
return E_ID;
Enter critical section
Take TCB
if (TCB == NULL)
return E_NOEXS;
Take status from TCB
if (status is sleeping) {
make the status as Ready
if (Sleeping with TIMEOUT)
remove task from Timer queue
if (Not suspended) {
add task to ready queue and dispatch
return;
} /* Else, suspended */
Exit critical section and just return E_OK;
}
/* Not sleeping */
if (status is not Dormant) {
increment pending wakeup count
if (pending wakeup count does not exceed maximum)
exit critical section and return E_OK
/* else, exceeded */
assign wakeup count to the maximum
exit critical section and return E_QOVR;
}
/* Dormant */
exit critical section and return E_OBJ;
}
Cancel Wakeup Task
ER can_wup(ID tskid)
{
if (tskid is TSK_SELF)
Take taskid from Ready Queue[0]
if (Task ID is greater than maximum of Task ID)
return E_ID;
Enter critical section
Take TCB
if (TCB == NULL)
return E_NOEXS;
else if (Task status is Dormat)
return E_OBJ;
else {
Take backup of number of pending wakeup requests
make pending wakeup counts as zero
}
Exit critical section
return saved wake up counts;
}
ER tslp_tsk(TMO tmout)
{
Sanity check of context and arguments
if (interrupt context or dispatch disabled state or Timer or overrun
handlers)
return E_CTX;
Take Task ID of current running task
Take TCB
Enter critical section
Take number of pending wakeups
if (No pending wakeup) {
if (Not polling) {
if (timeout is NOT FOREVER) {
add taks to timer queue;
make tcb status as SLEEP with TIMEOUT
} else /* forever timeout */
make tcb status just as SLEEP
}
remove task from Ready queue and dispatch
/* critical section is exit inside dispatch */
return error code from dispatch;
}
/* else, Polling */ {
Exit critical section and return E_TMOUT; /* ?? Not needed */
/* No polling service call is provided for slp_tsk- ITRON spec */
}
/* else, pending wakeups */
Decrement the number of pending wake-ups by 1
Exit critical section and return E_OK;
}
Wakeup Task
ER wup_tsk(ID tskid)
{
if (tskid is TSK_SELF)
Take taskid from Ready Queue[0]
if (Task ID is greater than maximum of Task ID)
return E_ID;
Enter critical section
Take TCB
if (TCB == NULL)
return E_NOEXS;
Take status from TCB
if (status is sleeping) {
make the status as Ready
if (Sleeping with TIMEOUT)
remove task from Timer queue
if (Not suspended) {
add task to ready queue and dispatch
return;
} /* Else, suspended */
Exit critical section and just return E_OK;
}
/* Not sleeping */
if (status is not Dormant) {
increment pending wakeup count
if (pending wakeup count does not exceed maximum)
exit critical section and return E_OK
/* else, exceeded */
assign wakeup count to the maximum
exit critical section and return E_QOVR;
}
/* Dormant */
exit critical section and return E_OBJ;
}
Cancel Wakeup Task
ER can_wup(ID tskid)
{
if (tskid is TSK_SELF)
Take taskid from Ready Queue[0]
if (Task ID is greater than maximum of Task ID)
return E_ID;
Enter critical section
Take TCB
if (TCB == NULL)
return E_NOEXS;
else if (Task status is Dormat)
return E_OBJ;
else {
Take backup of number of pending wakeup requests
make pending wakeup counts as zero
}
Exit critical section
return saved wake up counts;
}
No comments:
Post a Comment