Ucos ii Task Management II: restore a task

Source: Internet
Author: User

 

Ucos ii Task Management II: restore a task

After a task is suspended, it needs to be restored and called to be executed again.

Ostaskresume () function implementation. Like ostasksuspend (), only one parameter is required to call ostaskresume (), that is, the priority. For example, ostaskresume (5) is a task with a recovery priority of 5.

Int8u ostaskresume (int8u PRIO)

{

OS _tcb * ptcb;

 

 

If (PRIO> = OS _lowest_prio) {(1)

Return (OS _prio_invalid );

}

OS _enter_critical ();

If (ptcb = ostcbpriotbl [PRIO]) = (OS _tcb *) 0) {(2)

OS _exit_critical ();

Return (OS _task_resume_prio );

} Else {

If (ptcb-> ostcbstat & OS _stat_suspend) {(3)

If (ptcb-> ostcbstat & = ~ OS _stat_suspend) = OS _stat_rdy) & (4)

(Ptcb-> ostcbdly = 0) {(5)

Osrdygrp | = ptcb-> ostcbbity; (6)

Osrdytbl [ptcb-> ostcby] | = ptcb-> ostcbbitx;

OS _exit_critical ();

Ossched (); (7)

} Else {

OS _exit_critical ();

}

Return (OS _no_err );

} Else {

OS _exit_critical ();

Return (OS _task_not_suincluded );

}

}

}

The implementation of task recovery is basically a reverse operation of task suspension.

 

Because ostasksuspend () cannot suspend idle tasks, you must ensure that your applications are not restoring idle tasks [(1)]. Note: This test also ensures that the user is not performing a task with a recovery priority of OS _prio_self (OS _prio_self is defined as 0xff, which is always larger than OS _lowest_prio ).

The task to be restored must exist because the task control block OS _tcb [(2)] that you want to operate on must be suspended [(3)]. Ostaskresume () cancels the pending [(4)] by clearing the OS _stat_suspend bit in the ostcbstat field. To make the task ready, the OS _tcbdly field must be 0 [(5)], because there is no mark in ostcbstat that the task is waiting for the delay to expire. The task is ready only when both of the preceding conditions are met [(6)]. Finally, the task scheduler checks whether the priority of the recovered task is higher than that of the task that calls this function [
(7)].

 

The most important of these two statements are:

Osrdygrp | = ptcb-> ostcbbity;

Osrdytbl [ptcb-> ostcby] | = ptcb-> ostcbbitx;

The role of the program is to re-Add the task to the ready table.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.