X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=mware%2Flist.h;h=d8e2d7bcebcde5e4ca52acb0b45781fd67833fb5;hb=4fff2b5aec13bb0b46d17e336a988a2212ec2104;hp=c596f1d5b00805a5349cef70c9b8ecf72046a806;hpb=c050bdecde22c15215c52b55a6107cf74147508c;p=bertos.git diff --git a/mware/list.h b/mware/list.h old mode 100755 new mode 100644 index c596f1d5..d8e2d7bc --- a/mware/list.h +++ b/mware/list.h @@ -1,9 +1,34 @@ -/*! +/** * \file * * * \version $Id$ @@ -15,6 +40,18 @@ /*#* *#* $Log$ + *#* Revision 1.20 2006/07/19 12:56:28 bernie + *#* Convert to new Doxygen style. + *#* + *#* Revision 1.19 2006/03/20 17:50:29 bernie + *#* Fix typo. + *#* + *#* Revision 1.18 2006/02/27 22:40:21 bernie + *#* Add support for poor pre-C99 compilers. + *#* + *#* Revision 1.17 2006/02/24 01:18:34 bernie + *#* LIST_ENQUEUE(): New macro; Remove obsolete names. + *#* *#* Revision 1.16 2006/01/23 23:10:38 bernie *#* REVERSE_FOREACH_NODE(): New macro; FOREACHNODE(): Rename to FOREACH_NODE. *#* @@ -71,7 +108,7 @@ #include /* INLINE */ #include /* ASSERT() */ -/*! +/** * This structure represents a node for bidirectional lists. * * Data is usually appended to nodes by making them the first @@ -83,7 +120,7 @@ typedef struct _Node struct _Node *pred; } Node; -/*! +/** * Head of a doubly-linked list of \c Node structs. * * Lists must be initialized with LIST_INIT() prior to use. @@ -98,8 +135,17 @@ typedef struct _List Node tail; } List; +/** + * Extended node for priority queues. + */ +typedef struct _PriNode +{ + Node link; + int pri; +} PriNode; + -/*! +/** * Template for a naked node in a list of \a T structures. * * To be used as data member in other structures: @@ -122,7 +168,7 @@ typedef struct _List * * LIST_INIT(&foo_list); * ADDHEAD(&foo_list, &foo1); - * INSERTBEFORE(&foo_list, &foo2); + * INSERT_BEFORE(&foo_list, &foo2); * FOREACH_NODE(fp, &foo_list) * fp->a = 10; * } @@ -132,11 +178,11 @@ typedef struct _List #define DECLARE_NODE_ANON(T) \ T *succ; T *pred; -/*! Declare a typesafe node for structures of type \a T. */ +/** Declare a typesafe node for structures of type \a T. */ #define DECLARE_NODE_TYPE(T) \ typedef struct T##Node { T *succ; T *pred; } T##Node -/*! Template for a list of \a T structures. */ +/** Template for a list of \a T structures. */ #define DECLARE_LIST_TYPE(T) \ DECLARE_NODE_TYPE(T); \ typedef struct T##List { \ @@ -147,21 +193,28 @@ typedef struct _List #define NODE_TYPE(T) T##Node #define LIST_TYPE(T) T##List -/*! +/** * Get a pointer to the first node in a list. * * If \a l is empty, result points to l->tail. */ #define LIST_HEAD(l) ((l)->head.succ) -/*! +/** * Get a pointer to the last node in a list. * * If \a l is empty, result points to l->head. */ #define LIST_TAIL(l) ((l)->tail.pred) -/*! +// TODO: move in compiler.h +#if COMPILER_TYPEOF + #define TYPEOF_OR_VOIDPTR(type) typeof(type) +#else + #define TYPEOF_OR_VOIDPTR(type) void * +#endif + +/** * Iterate over all nodes in a list. * * This macro generates a "for" statement using the following parameters: @@ -170,14 +223,12 @@ typedef struct _List */ #define FOREACH_NODE(n, l) \ for( \ - (n) = (typeof(n))LIST_HEAD(l); \ + (n) = (TYPEOF_OR_VOIDPTR(n))LIST_HEAD(l); \ ((Node *)(n))->succ; \ - (n) = (typeof(n))(((Node *)(n))->succ) \ + (n) = (TYPEOF_OR_VOIDPTR(n))(((Node *)(n))->succ) \ ) -#define FOREACHNODE FOREACH_NODE /* OBSOLETE */ - -/*! +/** * Iterate backwards over all nodes in a list. * * This macro generates a "for" statement using the following parameters: @@ -186,22 +237,22 @@ typedef struct _List */ #define REVERSE_FOREACH_NODE(n, l) \ for( \ - (n) = (typeof(n))LIST_TAIL(l); \ + (n) = (TYPEOF_OR_VOIDPTR(n))LIST_TAIL(l); \ ((Node *)(n))->pred; \ - (n) = (typeof(n))(((Node *)(n))->pred) \ + (n) = (TYPEOF_OR_VOIDPTR(n))(((Node *)(n))->pred) \ ) -/*! Initialize a list. */ +/** Initialize a list. */ #define LIST_INIT(l) \ do { \ - (l)->head.succ = (typeof((l)->head.succ)) &(l)->tail; \ + (l)->head.succ = (TYPEOF_OR_VOIDPTR((l)->head.succ)) &(l)->tail; \ (l)->head.pred = NULL; \ (l)->tail.succ = NULL; \ - (l)->tail.pred = (typeof((l)->tail.pred)) &(l)->head; \ + (l)->tail.pred = (TYPEOF_OR_VOIDPTR((l)->tail.pred)) &(l)->head; \ } while (0) #ifdef _DEBUG - /*! Make sure that a list is valid (it was initialized and is not corrupted). */ + /** Make sure that a list is valid (it was initialized and is not corrupted). */ #define LIST_ASSERT_VALID(l) \ do { \ Node *n, *pred; \ @@ -224,7 +275,7 @@ typedef struct _List #define INVALIDATE_NODE(n) do {} while (0) #endif -/*! Add node to list head. */ +/** Add node to list head. */ #define ADDHEAD(l,n) \ do { \ ASSERT(l); \ @@ -235,7 +286,7 @@ typedef struct _List (n)->pred->succ = (n); \ } while (0) -/*! Add node to list tail. */ +/** Add node to list tail. */ #define ADDTAIL(l,n) \ do { \ ASSERT(l); \ @@ -246,7 +297,7 @@ typedef struct _List (l)->tail.pred = (n); \ } while (0) -/*! +/** * Insert node \a n before node \a ln. * * \note You can't pass in a list header as \a ln, but @@ -260,7 +311,7 @@ typedef struct _List (ln)->pred = (n); \ } while (0) -/*! +/** * Remove \a n from whatever list it is in. * * \note Removing a node that has not previously been @@ -273,10 +324,27 @@ typedef struct _List INVALIDATE_NODE(n); \ } while (0) -/*! Tell whether a list is empty. */ +/** Tell whether a list is empty. */ #define LIST_EMPTY(l) ( (void *)((l)->head.succ) == (void *)(&(l)->tail) ) -/*! +/** + * 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 { \ + PriNode *ln; \ + FOREACH_NODE(ln, (list)) \ + if (ln->pri < (node)->pri) \ + break; \ + INSERT_BEFORE(&(node)->link, &ln->link); \ + } while (0) + + +/** * Unlink a node from the head of the list \a l. * * \return Pointer to node, or NULL if the list was empty. @@ -296,7 +364,7 @@ INLINE Node *list_remHead(List *l) return n; } -/*! +/** * Unlink a node from the tail of the list \a l. * * \return Pointer to node, or NULL if the list was empty. @@ -316,11 +384,4 @@ INLINE Node *list_remTail(List *l) return n; } -/* OBSOLETE names */ -#define REMHEAD list_remHead -#define REMTAIL list_remTail -#define INSERTBEFORE INSERT_BEFORE -#define ISLISTEMPTY LIST_EMPTY - - #endif /* MWARE_LIST_H */