Re: [PATCH] add functions that are needed if you'd like to do something fifo alike with lists

Wilfried Goesgens <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
On Wed, Apr 19, 2006 at 12:43:47PM +0200, Alexander Malysh wrote:
> Heh, and again nack. see below...
> 
> indentation
> 
> >+	else +		item=GET(list, list->len-1);
> 
> ditto

all right the new way?

> 
> > +/*
> >+ * Return the item at position `pos'.
> >+ */
> 
> wrong comment
> 
changed to "Return the last item in the list."

Wilfried Gösgens
add_stackalike.c.diff (text/plain, 846 B)
--- ../../_gateway/gwlib/list.c	2005-02-11 16:35:48.000000000 +0100
+++ list.c	2006-04-19 16:16:29.000000000 +0200
@@ -298,6 +298,19 @@
     return item;
 }
 
+void *gwlist_get_last(List *list)
+{
+    void *item;
+
+    lock(list);
+	if (list->len==0)
+        item=NULL;
+	else 
+      item=GET(list, list->len-1);
+    unlock(list);
+    return item;
+}
+
 
 void *gwlist_extract_first(List *list)
 {
@@ -315,6 +328,22 @@
     return item;
 }
 
+void *gwlist_extract_last(List *list)
+{
+    void *item;
+
+    gw_assert(list != NULL);
+    lock(list);
+    if (list->len == 0)
+        item = NULL;
+    else {
+        item = GET(list, list->len-1);
+        delete_items_from_list(list, list->len-1, 1);
+    }
+    unlock(list);
+    return item;
+}
+
 
 List *gwlist_extract_matching(List *list, void *pat, gwlist_item_matches_t *cmp)
 {
add_stackalike.h.diff (text/plain, 726 B)
--- ../../_gateway/gwlib/list.h	2005-02-11 16:35:48.000000000 +0100
+++ list.h	2006-04-19 16:14:25.000000000 +0200
@@ -199,6 +199,11 @@
  */
 void *gwlist_get(List *list, long pos);
 
+/*
+ * Return the last item in the list.
+ */
+void *gwlist_get_last(List *list);
+
 
 /*
  * Remove and return the first item in the list. Return NULL if list is
@@ -207,6 +212,13 @@
  */
 void *gwlist_extract_first(List *list);
 
+/*
+ * Remove and return the last item in the list. Return NULL if list is
+ * empty. Note that unlike gwlist_consume, this won't sleep until there is
+ * something in the list.
+ */
+void *gwlist_extract_last(List *list);
+
 
 /*
  * Create a new list with items from `list' that match a pattern. The items
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.