瀏覽代碼

Add _list_insert_before and _list_insert_after macros

Samuel Thibault 10 年之前
父節點
當前提交
b44e48eca3
共有 1 個文件被更改,包括 12 次插入2 次删除
  1. 12 2
      src/common/list.h

+ 12 - 2
src/common/list.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2012  Université de Bordeaux
+ * Copyright (C) 2009-2012, 2015  Université de Bordeaux
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -42,8 +42,12 @@
  *   void		FOO_list_erase(struct FOO_list*, struct FOO*);
  *     * ajoute une élément en queue de liste
  *   void		FOO_list_push_back(struct FOO_list*, struct FOO*);
- *     * ajoute un élément en tête de list
+ *     * ajoute un élément en tête de liste
  *   void		FOO_list_push_front(struct FOO_list*, struct FOO*);
+ *     * ajoute un élément avant un élément
+ *   void		FOO_list_insert_before(struct FOO_list*, struct FOO*new, struct FOO*);
+ *     * ajoute un élément après un élément
+ *   void		FOO_list_insert_after(struct FOO_list*, struct FOO*new, struct FOO*);
  *     * ajoute la deuxième liste à la fin de la première liste
  *   struct FOO*	FOO_list_push_list_back(struct FOO_list*, struct FOO_list*);
  *     * ajoute la première liste au début de la deuxième liste
@@ -132,6 +136,12 @@
   /** @internal */static inline void ENAME##_list_push_back(struct ENAME##_list *l, struct ENAME *e) \
     { if(l->_head == NULL) l->_head = e; else l->_tail->_next = e; \
       e->_next = NULL; e->_prev = l->_tail; l->_tail = e; } \
+  /** @internal */static inline void ENAME##_list_insert_before(struct ENAME##_list *l, struct ENAME *e, struct ENAME *o) \
+    { struct ENAME *p = o->_prev; if (p) { p->_next = e; e->_prev = p; } else { l->_head = e; e->_prev = NULL; } \
+      e->_next = o; o->_prev = e; } \
+  /** @internal */static inline void ENAME##_list_insert_after(struct ENAME##_list *l, struct ENAME *e, struct ENAME *o) \
+    { struct ENAME *n = o->_next; if (n) { n->_prev = e; e->_next = n; } else { l->_tail = e; e->_next = NULL; } \
+      e->_prev = o; o->_next = e; } \
   /** @internal */static inline void ENAME##_list_push_list_front(struct ENAME##_list *l1, struct ENAME##_list *l2) \
     { if (l2->_head == NULL) { l2->_head = l1->_head; l2->_tail = l1->_tail; } \
       else if (l1->_head != NULL) { l1->_tail->_next = l2->_head; l2->_head->_prev = l1->_tail; l2->_head = l1->_head; } } \