From: Arnaud Giersch Date: Tue, 5 Dec 2017 21:10:57 +0000 (+0100) Subject: Hide xbt_swag under the hood of mmalloc, its only remaining user. X-Git-Tag: v3.18~132 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7820e0e1436e6b1c4968e2bb7653285a5a11b0bc Hide xbt_swag under the hood of mmalloc, its only remaining user. Only the functions actually used were kept. --- diff --git a/ChangeLog b/ChangeLog index f18d137b43..572eda3a2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,7 +7,7 @@ SimGrid (3.18) NOT RELEASED YET (target: December 24 2017) Mailbox::getCname() instead to get a char*. - Storage::getName() changed to return a std::string, use Storage::getCname() instead to get a char*. - - simgrid::s4u::allStorages() becomes + - simgrid::s4u::allStorages() becomes simgrid::s4u::getStorageList(whereTo) to have both allocation and deallocation of the map in user space. @@ -25,16 +25,17 @@ SimGrid (3.18) NOT RELEASED YET (target: December 24 2017) - xbt/file.h: xbt_basename(), xbt_dirname(), xbt_getline() - xbt/str.h: xbt_str_join() - xbt/heap.h: use std::priority_queue or boost::heap instead + - xbt/swag.h: use boost::intrusive::list instead PLUGINS: - New link_energy plugin for the consumption of the links. - All of the operations on files and storage contents have been packaged into a plugin (src/plugins/file_system). The current - public interface can be found in + public interface can be found in include/simgrid/plugins/file_system.h - To use these functions you now have to initialize the plugin by - calling MSG_storage_file_system_init() just after calling - MSG_init() or sg_storage_file_system_init() just after creating + To use these functions you now have to initialize the plugin by + calling MSG_storage_file_system_init() just after calling + MSG_init() or sg_storage_file_system_init() just after creating the Engine. XML @@ -130,7 +131,7 @@ SimGrid (3.16) Released June 22. 2017. When one wants to get the list of tasks whose states have changed during a simulation round, s/he has to allocate and free a dynar and use it as argument to this function. The former SD_simulate (double how_long) - now returns void. + now returns void. Virtual Machines - Allow multicore VMs, with the correct sharing (unless you overcommit) diff --git a/doc/doxygen/module-xbt.doc b/doc/doxygen/module-xbt.doc index d2ce9de344..2fa4c19890 100644 --- a/doc/doxygen/module-xbt.doc +++ b/doc/doxygen/module-xbt.doc @@ -16,7 +16,6 @@ - Data structures - \ref XBT_dynar - \ref XBT_dict - - \ref XBT_swag - \ref XBT_misc - \ref XBT_graph @@ -64,7 +63,6 @@ @{ */ /** @defgroup XBT_dynar Dynar: generic dynamic array */ /** @defgroup XBT_dict Dict: generic dictionnary */ - /** @defgroup XBT_swag Swag: O(1) set datatype */ /** @} */ diff --git a/doc/doxygen/uhood_arch.doc b/doc/doxygen/uhood_arch.doc index e75eb7815a..484026c327 100644 --- a/doc/doxygen/uhood_arch.doc +++ b/doc/doxygen/uhood_arch.doc @@ -75,8 +75,8 @@ It is a portable library providing some grounding features such as \ref XBT_log, \ref XBT_ex and \ref XBT_config. XBT also encompass the following convenient C data structures: -\ref XBT_dynar, \ref XBT_dict, and -\ref XBT_swag. The code is being migrated in C++ so you should probably want +\ref XBT_dynar and \ref XBT_dict. +The code is being migrated in C++ so you should probably want to use standard C++ containers instead of them if possible. It contains some C++ polyfills and utilities as well. diff --git a/include/xbt.h b/include/xbt.h index 5890af37f9..127ffe05ae 100644 --- a/include/xbt.h +++ b/include/xbt.h @@ -21,7 +21,6 @@ #include #include -#include #include #include diff --git a/include/xbt/swag.h b/include/xbt/swag.h deleted file mode 100644 index f56e8f64e3..0000000000 --- a/include/xbt/swag.h +++ /dev/null @@ -1,198 +0,0 @@ -/* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -/* Warning, this module is done to be efficient and performs tons of cast and dirty things. So avoid using it unless - * you really know what you are doing. */ - -#ifndef XBT_SWAG_H -#define XBT_SWAG_H - -#include "xbt/misc.h" -#include "xbt/sysdep.h" /* size_t */ - -SG_BEGIN_DECL() - -/** - * @addtogroup XBT_swag - * @brief a O(1) set based on linked lists - * - * Warning, this module is done to be efficient and performs tons of cast and dirty things. So make sure you know what - * you are doing while using it. - * It is basically a fifo but with restrictions so that it can be used as a set. Any operation (add, remove, belongs) - * is O(1) and no call to malloc/free is done. - * - * @deprecated If you are using C++, you might want to use - * `boost::intrusive::set` instead. - */ -/** @defgroup XBT_swag_type Swag types - @ingroup XBT_swag - - Specific set. - - These typedefs are public so that the compiler can do his job but believe me, you don't want to try to play with - those structs directly. Use them as an abstract datatype. -*/ -/* @{ */ -typedef struct xbt_swag_hookup { - void *next; - void *prev; -} s_xbt_swag_hookup_t; -/**< This type should be added to a type that is to be used in a swag. - * - * Whenever a new object with this struct is created, all fields have to be set to NULL - * - * Here is an example like that : - -\code -typedef struct foo { - s_xbt_swag_hookup_t set1_hookup; - s_xbt_swag_hookup_t set2_hookup; - - double value; -} s_foo_t, *foo_t; -... -{ - s_foo_t elem; - xbt_swag_t set1=NULL; - xbt_swag_t set2=NULL; - - set1 = xbt_swag_new(xbt_swag_offset(elem, set1_hookup)); - set2 = xbt_swag_new(xbt_swag_offset(elem, set2_hookup)); - -} -\endcode -*/ -typedef s_xbt_swag_hookup_t *xbt_swag_hookup_t; - -struct xbt_swag { - void *head; - void *tail; - size_t offset; - int count; -}; -typedef struct xbt_swag s_xbt_swag_t; -typedef struct xbt_swag* xbt_swag_t; -typedef const struct xbt_swag* const_xbt_swag_t; - -/**< A typical swag */ -/* @} */ - -/** @defgroup XBT_swag_func SWAG functions - * @ingroup XBT_swag - - * @{ - */ - -XBT_PUBLIC(xbt_swag_t) xbt_swag_new(size_t offset); -XBT_PUBLIC(void) xbt_swag_free(xbt_swag_t swag); -XBT_PUBLIC(void) xbt_swag_init(xbt_swag_t swag, size_t offset); - -/** - * \brief Makes a swag empty. - * \param swag a swag - * @hideinitializer - */ -#define xbt_swag_reset(swag) do {} while(xbt_swag_extract(swag)) - -/** - * \param obj the objet to insert in the swag - * \param swag a swag - * @hideinitializer - * - * insert \a obj in \a swag - */ -#define xbt_swag_insert(obj, swag) xbt_swag_insert_at_tail(obj, swag) - -XBT_PUBLIC(void) xbt_swag_insert_at_head(void *obj, xbt_swag_t swag); -XBT_PUBLIC(void) xbt_swag_insert_at_tail(void *obj, xbt_swag_t swag); -XBT_PUBLIC(void *) xbt_swag_remove(void *obj, xbt_swag_t swag); -XBT_PUBLIC(void *) xbt_swag_extract(xbt_swag_t swag); -XBT_PUBLIC(int) xbt_swag_size(const_xbt_swag_t swag); - -#define xbt_swag_getPrev(obj, offset) (((xbt_swag_hookup_t)(((char *) (obj)) + (offset)))->prev) -#define xbt_swag_getNext(obj, offset) (((xbt_swag_hookup_t)(((char *) (obj)) + (offset)))->next) -#define xbt_swag_belongs(obj, swag) (xbt_swag_getNext((obj), (swag)->offset) || (swag)->tail == (obj)) - -static inline void *xbt_swag_getFirst(const_xbt_swag_t swag) -{ - return (swag->head); -} - -/** - * \brief Offset computation - * \arg var a variable of type struct something - * \arg field a field of struct something - * \return the offset of \a field in struct something. - * @hideinitializer - * - * It is very similar to offsetof except that is done at runtime and that you have to declare a variable. Why defining - * such a macro then ? Because it is portable... - */ -#define xbt_swag_offset(var,field) ((char *)&( (var).field ) - (char *)&(var)) -/* @} */ - -/** - * \defgroup XBT_swag_curs Swag cursor - * @ingroup XBT_swag - - * Iterates over the whole swag. - * - * @{ */ - - /** @brief A simple swag iterator - * @param obj the indice of the loop - * @param swag what to iterate over - * @warning you cannot modify the \a swag while using this loop - * @hideinitializer */ -#ifndef __cplusplus -#define xbt_swag_foreach(obj,swag) \ - for((obj)=xbt_swag_getFirst((swag)); \ - (obj)!=NULL; \ - (obj)=xbt_swag_getNext((obj),(swag)->offset)) -#else -#define xbt_swag_foreach(obj,swag) \ - for((obj)=(decltype(obj)) xbt_swag_getFirst((swag)); \ - (obj)!=NULL; \ - (obj)=(decltype(obj)) xbt_swag_getNext((obj),(swag)->offset)) -#endif -/** - * @brief A safe swag iterator - * @param obj the indice of the loop - * @param obj_next the object that is right after (if any) \a obj in the swag - * @param swag what to iterate over - * @hideinitializer - - You can safely modify the \a swag while using this loop. - Well, safely... Err. You can remove \a obj without having any trouble at least. */ - -#ifndef __cplusplus - -#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)) ) - -#else - -#define xbt_swag_foreach_safe(obj,obj_next,swag) \ - for((obj) = (decltype(obj)) xbt_swag_getFirst((swag)), \ - ((obj)?(obj_next = (decltype(obj)) xbt_swag_getNext((obj),(swag)->offset)): \ - (obj_next=NULL)); \ - (obj) != NULL; \ - (obj) = obj_next, \ - ((obj)?(obj_next = (decltype(obj)) xbt_swag_getNext((obj),(swag)->offset)): \ - (obj_next=NULL)) ) - -#endif - -/* @} */ - -SG_END_DECL() - -#endif /* XBT_SWAG_H */ diff --git a/src/xbt/mmalloc/mm.c b/src/xbt/mmalloc/mm.c index be48e421d3..752f71f41c 100644 --- a/src/xbt/mmalloc/mm.c +++ b/src/xbt/mmalloc/mm.c @@ -4,7 +4,7 @@ behavior. It should also still be possible to build the library as a standard library with multiple objects. */ -/* Copyright (c) 2010, 2012-2014. The SimGrid Team. +/* Copyright (c) 2010, 2012-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -18,6 +18,7 @@ #include /* Prototypes for lseek, sbrk (maybe) */ #endif +#include "swag.c" #include "mfree.c" #include "mmalloc.c" #include "mrealloc.c" diff --git a/src/xbt/mmalloc/mmprivate.h b/src/xbt/mmalloc/mmprivate.h index 2fdc94c9bd..7d2a2e7235 100644 --- a/src/xbt/mmalloc/mmprivate.h +++ b/src/xbt/mmalloc/mmprivate.h @@ -16,12 +16,12 @@ #include #include +#include "swag.h" #include "src/internal_config.h" #include "xbt/xbt_os_thread.h" #include "xbt/mmalloc.h" #include "xbt/ex.h" #include "xbt/dynar.h" -#include "xbt/swag.h" #include #include diff --git a/src/xbt/mmalloc/swag.c b/src/xbt/mmalloc/swag.c new file mode 100644 index 0000000000..b9fb24ec83 --- /dev/null +++ b/src/xbt/mmalloc/swag.c @@ -0,0 +1,124 @@ +/* Copyright (c) 2004-2017. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +/* Warning, this module is done to be efficient and performs tons of + cast and dirty things. So avoid using it unless you really know + what you are doing. */ + +/* This type should be added to a type that is to be used in such a swag */ + +#include "swag.h" +#include "xbt/asserts.h" + +#define xbt_swag_getPrev(obj, offset) (((xbt_swag_hookup_t)(((char*)(obj)) + (offset)))->prev) +#define xbt_swag_getNext(obj, offset) (((xbt_swag_hookup_t)(((char*)(obj)) + (offset)))->next) +#define xbt_swag_belongs(obj, swag) (xbt_swag_getNext((obj), (swag)->offset) || (swag)->tail == (obj)) + +static inline void *xbt_swag_getFirst(const_xbt_swag_t swag) +{ + return (swag->head); +} + +/* + * \brief Offset computation + * \arg var a variable of type struct something + * \arg field a field of struct something + * \return the offset of \a field in struct something. + * @hideinitializer + * + * It is very similar to offsetof except that is done at runtime and that you have to declare a variable. Why defining + * such a macro then ? Because it is portable... + */ +#define xbt_swag_offset(var, field) ((char*)&((var).field) - (char*)&(var)) +/* @} */ + +/* Creates a new swag. + * \param swag the swag to initialize + * \param offset where the hookup is located in the structure + * \see xbt_swag_offset + * + * Usage : xbt_swag_init(swag,&obj.setA-&obj); + */ +static inline void xbt_swag_init(xbt_swag_t swag, size_t offset) +{ + swag->tail = NULL; + swag->head = NULL; + swag->offset = offset; + swag->count = 0; +} + +/* + * \param obj the objet to insert in the swag + * \param swag a swag + * + * insert (at the tail... you probably had a very good reason to do that, I hope you know what you're doing) \a obj in + * \a swag + */ +static inline void xbt_swag_insert(void *obj, xbt_swag_t swag) +{ + xbt_assert(!xbt_swag_belongs(obj, swag) || swag->tail, + "This object belongs to an empty swag! Did you correctly initialize the object's hookup?"); + + if (!swag->head) { + xbt_assert(!(swag->tail), "Inconsistent swag."); + swag->head = obj; + swag->tail = obj; + swag->count++; + } else if (obj != swag->tail && !xbt_swag_getNext(obj, swag->offset)) { + xbt_swag_getPrev(obj, swag->offset) = swag->tail; + xbt_swag_getNext(swag->tail, swag->offset) = obj; + swag->tail = obj; + swag->count++; + } +} + +/* + * \param obj the objet to remove from the swag + * \param swag a swag + * \return \a obj if it was in the \a swag and NULL otherwise + * + * removes \a obj from \a swag + */ +static inline void *xbt_swag_remove(void *obj, xbt_swag_t swag) +{ + if (!obj) + return NULL; + + size_t offset = swag->offset; + void* prev = xbt_swag_getPrev(obj, offset); + void* next = xbt_swag_getNext(obj, offset); + + if (prev) { + xbt_swag_getNext(prev, offset) = next; + xbt_swag_getPrev(obj, offset) = NULL; + if (next) { + xbt_swag_getPrev(next, offset) = prev; + xbt_swag_getNext(obj, offset) = NULL; + } else { + swag->tail = prev; + } + swag->count--; + } else if (next) { + xbt_swag_getPrev(next, offset) = NULL; + xbt_swag_getNext(obj, offset) = NULL; + swag->head = next; + swag->count--; + } else if (obj == swag->head) { + swag->head = swag->tail = NULL; + swag->count--; + } + + return obj; +} + +/* + * \param swag a swag + * \return the number of objects in \a swag + */ +static inline int xbt_swag_size(const_xbt_swag_t swag) +{ + return (swag->count); +} diff --git a/src/xbt/mmalloc/swag.h b/src/xbt/mmalloc/swag.h new file mode 100644 index 0000000000..e9903804ca --- /dev/null +++ b/src/xbt/mmalloc/swag.h @@ -0,0 +1,75 @@ +/* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +/* Warning, this module is done to be efficient and performs tons of cast and dirty things. So avoid using it unless + * you really know what you are doing. */ + +#ifndef XBT_SWAG_H +#define XBT_SWAG_H + +#include "xbt/sysdep.h" /* size_t */ + +/* + * XBT_swag: a O(1) set based on linked lists + * + * Warning, this module is done to be efficient and performs tons of cast and dirty things. So make sure you know what + * you are doing while using it. + * It is basically a fifo but with restrictions so that it can be used as a set. Any operation (add, remove, belongs) + * is O(1) and no call to malloc/free is done. + * + * @deprecated If you are using C++, you might want to use `boost::intrusive::set` instead. + */ + +/* Swag types + * + * Specific set. + * + * These typedefs are public so that the compiler can do his job but believe me, you don't want to try to play with + * those structs directly. Use them as an abstract datatype. + */ + +typedef struct xbt_swag_hookup { + void *next; + void *prev; +} s_xbt_swag_hookup_t; + +/* This type should be added to a type that is to be used in a swag. + * + * Whenever a new object with this struct is created, all fields have to be set to NULL + * + * Here is an example like that : + +\code +typedef struct foo { + s_xbt_swag_hookup_t set1_hookup; + s_xbt_swag_hookup_t set2_hookup; + + double value; +} s_foo_t, *foo_t; +... +{ + s_foo_t elem; + xbt_swag_t set1=NULL; + xbt_swag_t set2=NULL; + + set1 = xbt_swag_new(xbt_swag_offset(elem, set1_hookup)); + set2 = xbt_swag_new(xbt_swag_offset(elem, set2_hookup)); + +} +\endcode +*/ +typedef s_xbt_swag_hookup_t *xbt_swag_hookup_t; + +struct xbt_swag { + void *head; + void *tail; + size_t offset; + int count; +}; +typedef struct xbt_swag s_xbt_swag_t; +typedef struct xbt_swag* xbt_swag_t; +typedef const struct xbt_swag* const_xbt_swag_t; + +#endif /* XBT_SWAG_H */ diff --git a/src/xbt/swag.c b/src/xbt/swag.c deleted file mode 100644 index 6bf90c0fab..0000000000 --- a/src/xbt/swag.c +++ /dev/null @@ -1,242 +0,0 @@ -/* Copyright (c) 2004-2017. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -/* Warning, this module is done to be efficient and performs tons of - cast and dirty things. So avoid using it unless you really know - what you are doing. */ - -/* This type should be added to a type that is to be used in such a swag */ - -#include "xbt/sysdep.h" -#include "xbt/log.h" -#include "xbt/swag.h" - -/** Creates a new swag. - * \param offset where the hookup is located in the structure - * \see xbt_swag_offset - * - * Usage : xbt_swag_new(&obj.setA-&obj); - */ -inline xbt_swag_t xbt_swag_new(size_t offset) -{ - xbt_swag_t swag = xbt_new0(s_xbt_swag_t, 1); - - xbt_swag_init(swag, offset); - - return swag; -} - -/** - * \param swag poor victim - * - * kilkil a swag but not it's content. If you do not understand why xbt_swag_free should not free its content, - * don't use swags. - */ -inline void xbt_swag_free(xbt_swag_t swag) -{ - free(swag); -} - -/** Creates a new swag. - * \param swag the swag to initialize - * \param offset where the hookup is located in the structure - * \see xbt_swag_offset - * - * Usage : xbt_swag_init(swag,&obj.setA-&obj); - */ -inline void xbt_swag_init(xbt_swag_t swag, size_t offset) -{ - swag->tail = NULL; - swag->head = NULL; - swag->offset = offset; - swag->count = 0; -} - -/** - * \param obj the objet to insert in the swag - * \param swag a swag - * - * insert (at the head... you probably had a very good reason to do that, I hope you know what you're doing) \a obj in - * \a swag - */ -inline void xbt_swag_insert_at_head(void *obj, xbt_swag_t swag) -{ - xbt_assert(!xbt_swag_belongs(obj, swag) || swag->tail, - "This object belongs to an empty swag! Did you correctly initialize the object's hookup?"); - - if (!swag->head) { - xbt_assert(!(swag->tail), "Inconsistent swag."); - swag->head = obj; - swag->tail = obj; - swag->count++; - } else if (obj != swag->head && !xbt_swag_getPrev(obj, swag->offset)) { - xbt_swag_getNext(obj, swag->offset) = swag->head; - xbt_swag_getPrev(swag->head, swag->offset) = obj; - swag->head = obj; - swag->count++; - } -} - -/** - * \param obj the objet to insert in the swag - * \param swag a swag - * - * insert (at the tail... you probably had a very good reason to do that, I hope you know what you're doing) \a obj in - * \a swag - */ -inline void xbt_swag_insert_at_tail(void *obj, xbt_swag_t swag) -{ - xbt_assert(!xbt_swag_belongs(obj, swag) || swag->tail, - "This object belongs to an empty swag! Did you correctly initialize the object's hookup?"); - - if (!swag->head) { - xbt_assert(!(swag->tail), "Inconsistent swag."); - swag->head = obj; - swag->tail = obj; - swag->count++; - } else if (obj != swag->tail && !xbt_swag_getNext(obj, swag->offset)) { - xbt_swag_getPrev(obj, swag->offset) = swag->tail; - xbt_swag_getNext(swag->tail, swag->offset) = obj; - swag->tail = obj; - swag->count++; - } -} - -/** - * \param obj the objet to remove from the swag - * \param swag a swag - * \return \a obj if it was in the \a swag and NULL otherwise - * - * removes \a obj from \a swag - */ -inline void *xbt_swag_remove(void *obj, xbt_swag_t swag) -{ - if (!obj) - return NULL; - - size_t offset = swag->offset; - void* prev = xbt_swag_getPrev(obj, offset); - void* next = xbt_swag_getNext(obj, offset); - - if (prev) { - xbt_swag_getNext(prev, offset) = next; - xbt_swag_getPrev(obj, offset) = NULL; - if (next) { - xbt_swag_getPrev(next, offset) = prev; - xbt_swag_getNext(obj, offset) = NULL; - } else { - swag->tail = prev; - } - swag->count--; - } else if (next) { - xbt_swag_getPrev(next, offset) = NULL; - xbt_swag_getNext(obj, offset) = NULL; - swag->head = next; - swag->count--; - } else if (obj == swag->head) { - swag->head = swag->tail = NULL; - swag->count--; - } - - return obj; -} - -/** - * \param swag a swag - * \return an object from the \a swag - */ -void *xbt_swag_extract(xbt_swag_t swag) -{ - if (!swag->head) - return NULL; - - size_t offset = swag->offset; - void* obj = swag->head; - - if (obj == swag->tail) { /* special case */ - swag->head = swag->tail = NULL; - } else { - swag->head = xbt_swag_getNext(obj, offset); - xbt_swag_getPrev(swag->head, offset) = NULL; - xbt_swag_getNext(obj, offset) = NULL; - } - (swag->count)--; - - return obj; -} - -/** - * \param swag a swag - * \return the number of objects in \a swag - */ -inline int xbt_swag_size(const_xbt_swag_t swag) -{ - return (swag->count); -} - -#ifdef SIMGRID_TEST - -XBT_TEST_SUITE("swag", "Swag data container"); - -typedef struct { - s_xbt_swag_hookup_t setA; - s_xbt_swag_hookup_t setB; - const char *name; -} shmurtz, s_shmurtz_t, *shmurtz_t; - - -XBT_TEST_UNIT("basic", test_swag_basic, "Basic usage") -{ - shmurtz_t obj1, obj2, obj; - xbt_swag_t setA, setB; - - obj1 = xbt_new0(s_shmurtz_t, 1); - obj2 = xbt_new0(s_shmurtz_t, 1); - - obj1->name = "Obj 1"; - obj2->name = "Obj 2"; - - xbt_test_add("Basic usage"); - xbt_test_log("%p %p %ld\n", obj1, &(obj1->setB), (long) ((char *) &(obj1->setB) - (char *) obj1)); - - setA = xbt_swag_new(xbt_swag_offset(*obj1, setA)); - setB = xbt_swag_new(xbt_swag_offset(*obj1, setB)); - - xbt_swag_insert(obj1, setA); - xbt_swag_insert(obj1, setB); - xbt_swag_insert(obj2, setA); - xbt_swag_insert(obj2, setB); - - xbt_test_assert(xbt_swag_remove(NULL, setB) == NULL); - xbt_test_assert(xbt_swag_remove(obj1, setB) == obj1); - - xbt_test_add("Traverse set A"); - xbt_swag_foreach(obj, setA) { - xbt_test_log("Saw: %s", obj->name); - } - - xbt_test_add("Traverse set B"); - xbt_swag_foreach(obj, setB) { - xbt_test_log("Saw: %s", obj->name); - } - - xbt_test_add("Ensure set content and length"); - xbt_test_assert(xbt_swag_belongs(obj1, setA)); - xbt_test_assert(xbt_swag_belongs(obj2, setA)); - - xbt_test_assert(!xbt_swag_belongs(obj1, setB)); - xbt_test_assert(xbt_swag_belongs(obj2, setB)); - - xbt_test_assert(xbt_swag_size(setA) == 2); - xbt_test_assert(xbt_swag_size(setB) == 1); - - xbt_swag_free(setA); - xbt_swag_free(setB); - - xbt_free(obj1); - xbt_free(obj2); -} -#endif /* SIMGRID_TEST */ diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 9480a62b9e..814ba57c84 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -80,6 +80,8 @@ set(EXTRA_DIST src/xbt/mmalloc/mmorecore.c src/xbt/mmalloc/mmprivate.h src/xbt/mmalloc/mrealloc.c + src/xbt/mmalloc/swag.c + src/xbt/mmalloc/swag.h tools/tesh/generate_tesh tools/lualib.patch teshsuite/lua/lua_platforms.tesh @@ -277,7 +279,6 @@ set(XBT_SRC src/xbt/parmap.cpp src/xbt/snprintf.c src/xbt/string.cpp - src/xbt/swag.c src/xbt/xbt_log_appender_file.c src/xbt/xbt_log_layout_format.c src/xbt/xbt_log_layout_simple.c @@ -737,7 +738,6 @@ set(headers_to_install include/xbt/signal.hpp include/xbt/str.h include/xbt/string.hpp - include/xbt/swag.h include/xbt/synchro.h include/xbt/sysdep.h include/xbt/system_error.hpp diff --git a/tools/cmake/Distrib.cmake b/tools/cmake/Distrib.cmake index aacd81fc33..a4ca2968bf 100644 --- a/tools/cmake/Distrib.cmake +++ b/tools/cmake/Distrib.cmake @@ -344,7 +344,6 @@ add_custom_target(maintainer-clean COMMAND ${CMAKE_COMMAND} -E remove -f src/ex_unit.c COMMAND ${CMAKE_COMMAND} -E remove -f src/set_unit.c COMMAND ${CMAKE_COMMAND} -E remove -f src/simgrid_units_main.c - COMMAND ${CMAKE_COMMAND} -E remove -f src/swag_unit.c COMMAND ${CMAKE_COMMAND} -E remove -f src/xbt_str_unit.c COMMAND ${CMAKE_COMMAND} -E remove -f src/xbt_synchro_unit.c WORKING_DIRECTORY "${CMAKE_HOME_DIRECTORY}") diff --git a/tools/cmake/GCCFlags.cmake b/tools/cmake/GCCFlags.cmake index f093b3b84b..d00bb4039d 100644 --- a/tools/cmake/GCCFlags.cmake +++ b/tools/cmake/GCCFlags.cmake @@ -154,7 +154,7 @@ if(enable_model-checking AND enable_compile_optimizations) src/xbt/log.c src/xbt/xbt_log_appender_file.c src/xbt/xbt_log_layout_format.c src/xbt/xbt_log_layout_simple.c src/xbt/dict.cpp src/xbt/dict_elm.c src/xbt/dict_cursor.c - src/xbt/dynar.cpp src/xbt/swag.c + src/xbt/dynar.cpp src/xbt/xbt_str.cpp src/xbt/snprintf.c src/xbt/xbt_os_time.c src/xbt/xbt_os_thread.c src/xbt/backtrace_linux.cpp diff --git a/tools/cmake/UnitTesting.cmake b/tools/cmake/UnitTesting.cmake index 16701f711a..43af6555a6 100644 --- a/tools/cmake/UnitTesting.cmake +++ b/tools/cmake/UnitTesting.cmake @@ -9,7 +9,6 @@ set(FILES_CONTAINING_UNITTESTS src/xbt/ex.cpp src/xbt/dynar.cpp src/xbt/dict.cpp - src/xbt/swag.c src/xbt/xbt_str.cpp src/xbt/config.cpp )