git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@486
48e7efb5-ca39-0410-a469-
dd3cf9ba447f
xbt_fifo_t xbt_fifo_new(void);
void xbt_fifo_free(xbt_fifo_t);
xbt_fifo_t xbt_fifo_new(void);
void xbt_fifo_free(xbt_fifo_t);
-void xbt_fifo_push(xbt_fifo_t, void *);
+xbt_fifo_item_t xbt_fifo_push(xbt_fifo_t, void *);
void *xbt_fifo_pop(xbt_fifo_t);
void *xbt_fifo_pop(xbt_fifo_t);
-void xbt_fifo_unshift(xbt_fifo_t, void *);
+xbt_fifo_item_t xbt_fifo_unshift(xbt_fifo_t, void *);
void *xbt_fifo_shift(xbt_fifo_t);
void *xbt_fifo_shift(xbt_fifo_t);
+void xbt_fifo_push_item(xbt_fifo_t, xbt_fifo_item_t);
+xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t);
+void xbt_fifo_unshift_item(xbt_fifo_t, xbt_fifo_item_t);
+xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t);
+
void xbt_fifo_remove(xbt_fifo_t, void *);
void xbt_fifo_remove_item(xbt_fifo_t, xbt_fifo_item_t);
void xbt_fifo_remove(xbt_fifo_t, void *);
void xbt_fifo_remove_item(xbt_fifo_t, xbt_fifo_item_t);
under the terms of the license (GNU LGPL) which comes with this package. */
#include "xbt/sysdep.h"
under the terms of the license (GNU LGPL) which comes with this package. */
#include "xbt/sysdep.h"
#include "fifo_private.h"
/*
#include "fifo_private.h"
/*
* xbt_fifo_push()
* at the tail
*/
* xbt_fifo_push()
* at the tail
*/
-void xbt_fifo_push(xbt_fifo_t l, void *t)
+xbt_fifo_item_t xbt_fifo_push(xbt_fifo_t l, void *t)
+{
+ xbt_fifo_item_t new;
+
+ new = xbt_fifo_newitem();
+ new->content = t;
+
+ xbt_fifo_push_item(l,new);
+ return new;
+}
+
+/*
+ * xbt_fifo_pop()
+ * from the tail
+ */
+void *xbt_fifo_pop(xbt_fifo_t l)
+{
+ xbt_fifo_item_t item;
+ void *content;
+
+ item = xbt_fifo_pop_item(l);
+ if(item==NULL) return NULL;
+
+ content = item->content;
+ xbt_fifo_freeitem(item);
+ return content;
+}
+
+/*
+ * xbt_fifo_unshift()
+ * at the head
+ */
+xbt_fifo_item_t xbt_fifo_unshift(xbt_fifo_t l, void *t)
new = xbt_fifo_newitem();
new->content = t;
new = xbt_fifo_newitem();
new->content = t;
+ xbt_fifo_unshift_item(l,new);
+ return new;
+}
+
+/*
+ * xbt_fifo_shift()
+ * from the head
+ */
+void *xbt_fifo_shift(xbt_fifo_t l)
+{
+ xbt_fifo_item_t item;
+ void *content;
+
+ item = xbt_fifo_shift_item(l);
+ if(l==NULL) return NULL;
+
+ content = item->content;
+ xbt_fifo_freeitem(item);
+ return content;
+}
+
+/*
+ * xbt_fifo_push_item()
+ * at the tail
+ */
+void xbt_fifo_push_item(xbt_fifo_t l, xbt_fifo_item_t new)
+{
+ (l->count)++;
if (l->head == NULL) {
l->head = new;
l->tail = new;
if (l->head == NULL) {
l->head = new;
l->tail = new;
new->prev = l->tail;
new->prev->next = new;
l->tail = new;
new->prev = l->tail;
new->prev->next = new;
l->tail = new;
-void *xbt_fifo_pop(xbt_fifo_t l)
+xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t l)
if (l->tail == NULL)
return NULL;
item = l->tail;
if (l->tail == NULL)
return NULL;
item = l->tail;
- content = item->content;
l->tail = item->prev;
if (l->tail == NULL)
l->tail = item->prev;
if (l->tail == NULL)
else
l->tail->next = NULL;
else
l->tail->next = NULL;
- xbt_fifo_freeitem(item);
+ * xbt_fifo_unshift_item()
-void xbt_fifo_unshift(xbt_fifo_t l, void *t)
+void xbt_fifo_unshift_item(xbt_fifo_t l, xbt_fifo_item_t new)
- new = xbt_fifo_newitem();
- new->content = t;
if (l->head == NULL) {
l->head = new;
l->tail = new;
if (l->head == NULL) {
l->head = new;
l->tail = new;
+ * xbt_fifo_shift_item()
-void *xbt_fifo_shift(xbt_fifo_t l)
+xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t l)
if (l->head == NULL)
return NULL;
item = l->head;
if (l->head == NULL)
return NULL;
item = l->head;
- content = item->content;
l->head = item->next;
if (l->head == NULL)
l->head = item->next;
if (l->head == NULL)
else
l->head->prev = NULL;
else
l->head->prev = NULL;
- xbt_fifo_freeitem(item);
continue;
/* remove the item */
xbt_fifo_remove_item(l, current);
continue;
/* remove the item */
xbt_fifo_remove_item(l, current);
+ xbt_fifo_freeitem(current);
/* WILL NOT REMOVE DUPLICATES */
break;
}
/* WILL NOT REMOVE DUPLICATES */
break;
}
if (l->head == l->tail) { /* special case */
l->head = NULL;
l->tail = NULL;
if (l->head == l->tail) { /* special case */
l->head = NULL;
l->tail = NULL;
- xbt_fifo_freeitem(current);
if (current == l->head) { /* It's the head */
l->head = current->next;
l->head->prev = NULL;
if (current == l->head) { /* It's the head */
l->head = current->next;
l->head->prev = NULL;
- xbt_fifo_freeitem(current);
} else if (current == l->tail) { /* It's the tail */
l->tail = current->prev;
l->tail->next = NULL;
} else if (current == l->tail) { /* It's the tail */
l->tail = current->prev;
l->tail->next = NULL;
- xbt_fifo_freeitem(current);
} else { /* It's in the middle */
current->prev->next = current->next;
current->next->prev = current->prev;
} else { /* It's in the middle */
current->prev->next = current->next;
current->next->prev = current->prev;
- xbt_fifo_freeitem(current);
#define xbt_fifo_getNextitem(i) ((i)?(i)->next:NULL)
#define xbt_fifo_getPrevitem(i) ((i)?(i)->prev:NULL)
#define xbt_fifo_getItemcontent(i) ((i)?(i)->content:NULL)
#define xbt_fifo_getNextitem(i) ((i)?(i)->next:NULL)
#define xbt_fifo_getPrevitem(i) ((i)?(i)->prev:NULL)
#define xbt_fifo_getItemcontent(i) ((i)?(i)->content:NULL)
+#define xbt_fifo_Itemcontent(i) ((i)->content)
#define xbt_fifo_setItemcontent(i,v) (i->content=v)
#define xbt_fifo_setItemcontent(i,v) (i->content=v)