+/**
+ * Track ready processes.
+ *
+ * Access to this list must be performed with interrupts disabled
+ */
+extern REGISTER List proc_ready_list;
+
+#if CONFIG_KERN_PRI
+ #define prio_next() (LIST_EMPTY(&proc_ready_list) ? INT_MIN : \
+ ((PriNode *)LIST_HEAD(&proc_ready_list))->pri)
+ #define prio_proc(proc) (proc->link.pri)
+ #define prio_curr() prio_proc(current_process)
+
+ #define SCHED_ENQUEUE_INTERNAL(proc) \
+ LIST_ENQUEUE(&proc_ready_list, &(proc)->link)
+ #define SCHED_ENQUEUE_HEAD_INTERNAL(proc) \
+ LIST_ENQUEUE_HEAD(&proc_ready_list, &(proc)->link)
+#else
+ #define prio_next() 0
+ #define prio_proc(proc) 0
+ #define prio_curr() 0
+
+ #define SCHED_ENQUEUE_INTERNAL(proc) ADDTAIL(&proc_ready_list, &(proc)->link)
+ #define SCHED_ENQUEUE_HEAD_INTERNAL(proc) ADDHEAD(&proc_ready_list, &(proc)->link)
+#endif
+
+/**
+ * Enqueue a process in the ready list.
+ *
+ * Always use this macro to instert a process in the ready list, as its
+ * might vary to implement a different scheduling algorithms.
+ *
+ * \note Access to the scheduler ready list must be performed with
+ * interrupts disabled.
+ */
+#define SCHED_ENQUEUE(proc) do { \
+ IRQ_ASSERT_DISABLED(); \
+ LIST_ASSERT_VALID(&proc_ready_list); \
+ SCHED_ENQUEUE_INTERNAL(proc); \
+ } while (0)
+
+#define SCHED_ENQUEUE_HEAD(proc) do { \
+ IRQ_ASSERT_DISABLED(); \
+ LIST_ASSERT_VALID(&proc_ready_list); \
+ SCHED_ENQUEUE_HEAD_INTERNAL(proc); \
+ } while (0)
+
+
+#if 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_reenqueue(struct Process *proc)
+{
+ IRQ_ASSERT_DISABLED();
+ LIST_ASSERT_VALID(&proc_ready_list);
+ Node *n;
+ PriNode *pos = NULL;
+ FOREACH_NODE(n, &proc_ready_list)
+ {
+ if (n == &proc->link.link)
+ {
+ pos = (PriNode *)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(&proc_ready_list, &proc->link);
+ }
+}
+#endif //CONFIG_KERN_PRI