diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index 11cdf855278..8bb457fd79d 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -262,52 +262,56 @@ static inline void nxsched_blocked_setpriority(FAR struct tcb_s *tcb, int nxsched_set_priority(FAR struct tcb_s *tcb, int sched_priority) { irqstate_t flags; + int ret = OK; /* Verify that the requested priority is in the valid range */ if (sched_priority < SCHED_PRIORITY_MIN || sched_priority > SCHED_PRIORITY_MAX) { - return -EINVAL; + ret = -EINVAL; } - - /* We need to assure that there there is no interrupt activity while - * performing the following. - */ - - flags = enter_critical_section(); - - /* There are three major cases (and two sub-cases) that must be - * considered: - */ - - switch (tcb->task_state) + else { - /* CASE 1. The task is running and a context switch may be caused by - * the re-prioritization + /* We need to assure that there there is no interrupt activity while + * performing the following. */ - case TSTATE_TASK_RUNNING: - nxsched_running_setpriority(tcb, sched_priority); - break; + flags = enter_critical_section(); - /* CASE 2. The task is ready-to-run (but not running) and a context - * switch may be caused by the re-prioritization + /* There are three major cases (and two sub-cases) that must be + * considered: */ - case TSTATE_TASK_READYTORUN: - nxsched_readytorun_setpriority(tcb, sched_priority); - break; + switch (tcb->task_state) + { + /* CASE 1. The task is running and a context switch may be caused + * by the re-prioritization + */ - /* CASE 3. The task is not in the ready to run list. Changing its - * Priority cannot effect the currently executing task. - */ + case TSTATE_TASK_RUNNING: + nxsched_running_setpriority(tcb, sched_priority); + break; - default: - nxsched_blocked_setpriority(tcb, sched_priority); - break; - } + /* CASE 2. The task is ready-to-run (but not running) and a context + * switch may be caused by the re-prioritization + */ - leave_critical_section(flags); - return OK; + case TSTATE_TASK_READYTORUN: + nxsched_readytorun_setpriority(tcb, sched_priority); + break; + + /* CASE 3. The task is not in the ready to run list. Changing its + * Priority cannot effect the currently executing task. + */ + + default: + nxsched_blocked_setpriority(tcb, sched_priority); + break; + } + + leave_critical_section(flags); + } + + return ret; }