X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f58700be432433386a2502ca365345a1f5bf3098..91f0f8acd7bb93039252812ab45521b948ff50f4:/include/xbt/swag.h diff --git a/include/xbt/swag.h b/include/xbt/swag.h index a834d74f7c..5af75a74e6 100644 --- a/include/xbt/swag.h +++ b/include/xbt/swag.h @@ -8,7 +8,10 @@ what you are doing. */ /* This type should be added to a type that is to be used in such a swag */ -/* Whenever a new object with this struct is created, all fields have to be swag to NULL */ +/* 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; @@ -40,6 +43,15 @@ static __inline__ void *xbt_swag_getFirst(xbt_swag_t swag) #define xbt_swag_offset(var,field) ((char *)&( (var).field ) - (char *)&(var)) #define xbt_swag_foreach(obj,swag) \ - for((obj)=xbt_swag_getFirst((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)) )