From: lottaviano Date: Mon, 24 Aug 2009 17:19:08 +0000 (+0000) Subject: Fix proc_setPri(), which now correctly changes the priority of processes in the ready... X-Git-Tag: 2.2.0~190 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=ebaf963fb967c6511649cd8c348c56812214501f;p=bertos.git Fix proc_setPri(), which now correctly changes the priority of processes in the ready list. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2778 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/kern/proc.c b/bertos/kern/proc.c index 9a1e410b..7ce077b0 100644 --- a/bertos/kern/proc.c +++ b/bertos/kern/proc.c @@ -318,9 +318,9 @@ void proc_setPri(struct Process *proc, int pri) if (proc != CurrentProcess) { - //proc_forbid(); - //TODO: re-enqueue process - //pric_permit(); + proc_forbid(); + ATOMIC(SCHED_CHANGE_PRI(proc)); + proc_permit(); } } #endif // CONFIG_KERN_PRI diff --git a/bertos/kern/proc_p.h b/bertos/kern/proc_p.h index b148057c..54ea3710 100644 --- a/bertos/kern/proc_p.h +++ b/bertos/kern/proc_p.h @@ -47,6 +47,7 @@ #include #include /* for cpu_stack_t */ +#include // IRQ_ASSERT_DISABLED() #include @@ -132,6 +133,41 @@ extern REGISTER List ProcReadyList; SCHED_ENQUEUE_INTERNAL(proc); \ } while (0) +#ifdef CONFIG_KERN_PRI +/** + * Changes the priority of an already enqueued process. + * + * Searches and removes the process from the ready list, then uses LIST_ENQUEUE(() + * to insert again to fix priority. + * + * No action is performed for processes that aren't in the ready list, eg. in semaphore queues. + * + * \note Performance could be improved with a different implementation of priority list. + */ +INLINE void SCHED_CHANGE_PRI(struct Process *proc) +{ + IRQ_ASSERT_DISABLED(); + LIST_ASSERT_VALID(&ProcReadyList); + Node *n; + PriNode *pos = NULL; + FOREACH_NODE(n, &ProcReadyList) + { + if (n == &proc->link) + { + pos = n; + break; + } + } + + // only remove and enqueue again if process is already in the ready list + // otherwise leave it alone + if (pos) + { + REMOVE(&proc->link.link); + LIST_ENQUEUE(&ProcReadyList, &proc->link); + } +} +#endif //CONFIG_KERN_PRI /// Schedule another process *without* adding the current one to the ready list. void proc_switch(void);