Fix proc_setPri(), which now correctly changes the priority of processes in the ready...
authorlottaviano <lottaviano@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 24 Aug 2009 17:19:08 +0000 (17:19 +0000)
committerlottaviano <lottaviano@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 24 Aug 2009 17:19:08 +0000 (17:19 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2778 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/kern/proc.c
bertos/kern/proc_p.h

index 9a1e410b11ffc60cb74df36ff4f07f95a6515a22..7ce077b0c14f7974a2e9a76c95770489fd66ac5b 100644 (file)
@@ -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
index b148057c4a02fc256a5ade9505ef9986d246b34e..54ea3710acb4f5ca4c72831451b82dc8e9cf01bd 100644 (file)
@@ -47,6 +47,7 @@
 #include <cfg/compiler.h>
 
 #include <cpu/types.h>        /* for cpu_stack_t */
+#include <cpu/irq.h>          // IRQ_ASSERT_DISABLED()
 
 #include <struct/list.h>
 
@@ -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);