From cf3378588cedd2015f8c59b77fcc3fb8f9164ec8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 22 Dec 2007 11:34:39 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@155 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chlists.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/chlists.c') diff --git a/src/chlists.c b/src/chlists.c index 7994f8ac6..37db948b2 100644 --- a/src/chlists.c +++ b/src/chlists.c @@ -18,12 +18,29 @@ */ /** - * @addtogroup Messages + * @addtogroup Threads * @{ */ #include #ifndef CH_OPTIMIZE_SPEED +/* + * Inserts a thread into a priority ordered queue. + * @param tp the pointer to the thread to be inserted in the list + * @param tqp the pointer to the threads list header + * @note the insertion is done by scanning the list from the highest priority + * toward the lowest + */ +void prio_insert(Thread *tp, ThreadsQueue *tqp) { + + Thread *cp = tqp->p_next; + while ((cp != (Thread *)tqp) && (cp->p_prio >= tp->p_prio)) + cp = cp->p_next; + /* Insertion on p_prev.*/ + tp->p_prev = (tp->p_next = cp)->p_prev; + tp->p_prev->p_next = cp->p_prev = tp; +} + /* * Inserts a thread into a FIFO queue. * @param tp the pointer to the thread to be inserted in the list -- cgit v1.2.3