copied mono-api-diff.cs from mono-2-2 branch so new patch can be applied and history...
[mono.git] / eglib / src / gqueue.c
index 5347ad914fa4b4da6090497113bf15e83a8b6a07..2eedbf6f9f3d4973fdff90942610df59b2808e29 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Author:
  *   Duncan Mak (duncan@novell.com)
+ *   Gonzalo Paniagua Javier (gonzalo@novell.com)
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -23,7 +24,7 @@
  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
- * (C) 2006 Novell, Inc.
+ * Copyright (c) 2006-2009 Novell, Inc.
  *
  */
 
 gpointer
 g_queue_pop_head (GQueue *queue)
 {
-       gpointer head = NULL;
+       gpointer result;
+       GList *old_head;
 
-       if (queue->length != 0){
-               head = queue->head->data;
-               queue->head = queue->head->next;
-               queue->length--;                
-       }
+       if (!queue || queue->length == 0)
+               return NULL;
 
-       return head;
+       result = queue->head->data;
+       old_head = queue->head;
+       queue->head = old_head->next;
+       g_list_free_1 (old_head);
+
+       if (--queue->length)
+               queue->head->prev = NULL;
+       else
+               queue->tail = NULL;
+
+       return result;
 }
 
 gboolean
@@ -67,13 +76,24 @@ g_queue_push_head (GQueue *queue, gpointer head)
        queue->length ++;
 }
 
+void
+g_queue_push_tail (GQueue *queue, gpointer data)
+{
+       if (!queue)
+               return;
+
+       queue->tail = g_list_append (queue->tail, data);
+       if (queue->head == NULL)
+               queue->head = queue->tail;
+       else
+               queue->tail = queue->tail->next;
+       queue->length++;
+}
+
 GQueue *
 g_queue_new (void)
 {
-       GQueue *queue = g_new0 (GQueue, 1);
-       queue->length = 0;
-
-       return queue;
+       return g_new0 (GQueue, 1);
 }
 
 void