Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bug fix and add a xbt_swag_foreach_safe where you can remove objects from
[simgrid.git] / include / xbt / swag.h
index c235387..5af75a7 100644 (file)
@@ -11,6 +11,8 @@
 /* Whenever a new object with this struct is created, all fields have
    to be set to NULL */
 
+#include "xbt/sysdep.h"
+
 typedef struct xbt_swag_hookup {
   void *next;
   void *prev;
@@ -44,3 +46,12 @@ static __inline__ void *xbt_swag_getFirst(xbt_swag_t swag)
    for((obj)=xbt_swag_getFirst((swag));                       \
        (obj)!=NULL;                                           \
        (obj)=xbt_swag_getNext((obj),(swag)->offset))
+
+#define xbt_swag_foreach_safe(obj,obj_next,swag)                  \
+   for((obj)=xbt_swag_getFirst((swag)),                           \
+       ((obj)?(obj_next=xbt_swag_getNext((obj),(swag)->offset)):  \
+                (obj_next=NULL));                                \
+       (obj)!=NULL;                                               \
+       (obj)=obj_next,                                            \
+       ((obj)?(obj_next=xbt_swag_getNext((obj),(swag)->offset)):  \
+                 (obj_next=NULL))     )