X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fstruct%2Flist.h;h=c83063547ef42d3a55403bf1e1a4be3d5904a850;hb=b12629e93f75e4d8d0d750452d96d803f54489be;hp=05223caa01f70705e23435ce795c968470e98c80;hpb=9002e60f9cc2f2112180d706abe7dfc4f14ebf0f;p=bertos.git diff --git a/bertos/struct/list.h b/bertos/struct/list.h index 05223caa..c8306354 100644 --- a/bertos/struct/list.h +++ b/bertos/struct/list.h @@ -32,7 +32,6 @@ * * \brief General pourpose double-linked lists * - * \version $Id: list.h 1594 2008-08-10 12:20:10Z bernie $ * \author Bernie Innocenti */ @@ -216,6 +215,7 @@ typedef struct _PriNode #define INVALIDATE_NODE(n) ((n)->succ = (n)->pred = NULL) #else #define LIST_ASSERT_VALID(l) do {} while (0) + #define LIST_ASSERT_NOT_CONTAINS(list,node) do {} while (0) #define INVALIDATE_NODE(n) do {} while (0) #endif @@ -275,9 +275,24 @@ typedef struct _PriNode /** * Insert a priority node in a priority queue. * - * The new node is inserted immediately before the - * first node with lower priority or appended to - * the tail if no such node exists. + * The new node is inserted immediately before the first node with the same + * priority or appended to the tail if no such node exists. + */ +#define LIST_ENQUEUE_HEAD(list, node) \ + do { \ + PriNode *ln; \ + LIST_ASSERT_NOT_CONTAINS((list),(node)); \ + FOREACH_NODE(ln, (list)) \ + if (ln->pri <= (node)->pri) \ + break; \ + INSERT_BEFORE(&(node)->link, &ln->link); \ + } while (0) + +/** + * Insert a priority node in a priority queue. + * + * The new node is inserted immediately before the first node with lower + * priority or appended to the tail if no such node exists. */ #define LIST_ENQUEUE(list, node) \ do { \