From mboxrd@z Thu Jan 1 00:00:00 1970 From: lhh@sourceware.org Date: 26 Jan 2007 21:45:52 -0000 Subject: [Cluster-devel] cluster/rgmanager/include list.h Message-ID: <20070126214552.32129.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Changes by: lhh at sourceware.org 2007-01-26 21:45:48 Modified files: rgmanager/include: list.h Log message: Add list_prepend macro Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/include/list.h.diff?cvsroot=cluster&r1=1.4&r2=1.5 --- cluster/rgmanager/include/list.h 2006/06/02 17:37:10 1.4 +++ cluster/rgmanager/include/list.h 2007/01/26 21:45:46 1.5 @@ -29,6 +29,14 @@ } \ } while (0) + +#define list_prepend(list, newnode) \ +do { \ + list_insert(list, newnode); \ + *list = newnode; \ +} while (0) + + #define list_remove(list, oldnode) \ do { \ if (le(oldnode) == le(*list)) { \ @@ -46,6 +54,11 @@ } \ } while (0) +/* + list_do(list, node) { + stuff; + } while (!list_done(list, node)); + */ #define list_do(list, curr) \ if (*list && (curr = *list)) do @@ -53,9 +66,29 @@ (curr && (((curr = (void *)le(curr)->le_next)) && (curr == *list))) /* - list_do(list, node) { - stuff; - } while (!list_done(list, node)); + * list_for(list, tmp, counter) { + * stuff; + * } + * + * counter = # of items in list when done. + * * sets cnt to 0 before even checking list; + * * checks for valid list + * * traverses list, incrementing counter. If we get to the for loop, + * there must be at least one item in the list */ +#define list_for(list, curr, cnt) \ + if (!(cnt=0) && list && *list) \ + for (curr = *list; \ + (cnt == 0) || (curr != *list); \ + curr = (void*)le(curr)->le_next, \ + cnt++) + +#define list_for_rev(list, curr, cnt) \ + if (!(cnt=0) && list && *list) \ + for (curr = (void *)(le(*list)->le_prev); \ + (cnt == 0) || ((void *)curr != le(*list)->le_prev); \ + curr = (void*)(le(curr)->le_prev), \ + cnt++) + #endif