tasks that are finished and should constitute the return value of
SD_simulate.
+ XBT:
+ * Mallocators: allow value NULL for the reset function.
+
-- $date Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
SimGrid (3.6.2) stable; urgency=low
ADD_TEST(memcheck-tesh-simdag-parser-20 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test ./properties.xml --cfg=cpu/model:CpuTI --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
ADD_TEST(memcheck-tesh-simdag-parser-21 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test ./one_cluster_file.xml --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
ADD_TEST(memcheck-tesh-simdag-parser-22 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/is_router_test ./test_of_is_router.xml --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
+ADD_TEST(memcheck-tesh-simdag-parser-23 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test ./Two_clusters_rulebased.xml ONE_LINK --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
ADD_TEST(memcheck-tesh-simdag-parser-sym-full-0 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test one_cluster_fullduplex.xml FULL_LINK "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
ADD_TEST(memcheck-tesh-simdag-parser-sym-full-1 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test two_clusters_symmetric.xml FULL_LINK "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
ADD_TEST(memcheck-tesh-simdag-parser-sym-full-2 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test two_hosts_one_link_symmetrical.xml FULL_LINK "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
endif(HAVE_RAWCTX)
ADD_TEST(memcheck-msg-masterslave-vivaldi-thread-0 ${CMAKE_BINARY_DIR}/examples/msg/masterslave/masterslave_mailbox ${CMAKE_HOME_DIRECTORY}/examples/msg/../platforms/vivaldi.xml ${CMAKE_HOME_DIRECTORY}/examples/msg/masterslave/deployment_masterslave_vivaldi.xml --cfg=network/latency_factor:1.0 --cfg=network/bandwidth_factor:1.0 --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/)
-ADD_TEST(memcheck-msg-token-ring-thread-0 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
-ADD_TEST(memcheck-msg-token-ring-thread-1 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-thread-0 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-thread-1 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
if(HAVE_RAWCTX)
ADD_TEST(memcheck-msg-masterslave-vivaldi-raw-0 ${CMAKE_BINARY_DIR}/examples/msg/masterslave/masterslave_mailbox ${CMAKE_HOME_DIRECTORY}/examples/msg/../platforms/vivaldi.xml ${CMAKE_HOME_DIRECTORY}/examples/msg/masterslave/deployment_masterslave_vivaldi.xml --cfg=network/latency_factor:1.0 --cfg=network/bandwidth_factor:1.0 --cfg=contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/examples/msg/)
-ADD_TEST(memcheck-msg-token-ring-raw-0 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
-ADD_TEST(memcheck-msg-token-ring-raw-1 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-raw-0 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-raw-1 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
endif(HAVE_RAWCTX)
if(HAVE_UCONTEXT_H)
ADD_TEST(memcheck-msg-masterslave-vivaldi-ucontext-0 ${CMAKE_BINARY_DIR}/examples/msg/masterslave/masterslave_mailbox ${CMAKE_HOME_DIRECTORY}/examples/msg/../platforms/vivaldi.xml ${CMAKE_HOME_DIRECTORY}/examples/msg/masterslave/deployment_masterslave_vivaldi.xml --cfg=network/latency_factor:1.0 --cfg=network/bandwidth_factor:1.0 --cfg=contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/examples/msg/)
-ADD_TEST(memcheck-msg-token-ring-ucontext-0 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
-ADD_TEST(memcheck-msg-token-ring-ucontext-1 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-ucontext-0 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-ucontext-1 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
endif(HAVE_UCONTEXT_H)
ADD_TEST(memcheck-msg-masterslave-multicore-thread-0 ${CMAKE_BINARY_DIR}/examples/msg/masterslave/masterslave_mailbox ${CMAKE_HOME_DIRECTORY}/examples/msg/../platforms/multicore_machine.xml ${CMAKE_HOME_DIRECTORY}/examples/msg/masterslave/deployment_masterslave_mailbox_multicore.xml --cfg=cpu/model:Cas01_fullupdate --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/)
#! ./tesh
! output sort
-$ $SG_TEST_EXENV token_ring ${srcdir:=.}/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+$ $SG_TEST_EXENV ${bindir:=.}/token_ring ${srcdir:=.}/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (0:@) Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.
> [ 0.066240] (1:master@bob1.hamburger.edu) Send Data to "host1"
> [ 0.066240] (2:slave@bob3.hamburger.edu) Received "Token"
> [ 1.104000] (1:master@bob1.hamburger.edu) Received "Token"
! output sort
-$ $SG_TEST_EXENV token_ring ${srcdir:=.}/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n"
+$ $SG_TEST_EXENV ${bindir:=.}/token_ring ${srcdir:=.}/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (0:@) Configuration change: Set 'coordinates' to 'yes'
> [ 0.000000] (0:@) Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.
> [ 5.221778] (1:master@peer_100030591) Send Data to "host1"
typedef struct s_smx_context {
s_xbt_swag_hookup_t hookup;
xbt_main_func_t code;
- int argc;
- char **argv;
void_pfn_smxprocess_t cleanup_func;
- int iwannadie:1;
void *data; /* Here SIMIX stores the smx_process_t containing the context */
+ char **argv;
+ int argc;
+ int iwannadie:1;
} s_smx_ctx_base_t;
/* methods of this class */
*
* @{
*/
- /** @brief Configuration set are only special dynars. But don't rely on it, it may change. */
-typedef xbt_dynar_t xbt_cfg_t;
+/** @brief Configuration set's data type is opaque. */
+typedef void* xbt_cfg_t;
XBT_PUBLIC(void) xbt_cfg_set(xbt_cfg_t cfg, const char *name, ...);
XBT_PUBLIC(void) xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name,
*/
/** \brief Dictionary data type (opaque structure) */
-typedef struct xbt_dict_ *xbt_dict_t;
+typedef struct s_xbt_dict *xbt_dict_t;
XBT_PUBLIC(xbt_dict_t) xbt_dict_new(void);
XBT_PUBLIC(void) xbt_dict_free(xbt_dict_t * dict);
XBT_PUBLIC(unsigned int) xbt_dict_size(xbt_dict_t dict);
* @{ */
/** @brief Cursor on dictionaries (opaque type) */
-typedef struct xbt_dict_cursor_ *xbt_dict_cursor_t;
+typedef struct s_xbt_dict_cursor *xbt_dict_cursor_t;
XBT_PUBLIC(xbt_dict_cursor_t) xbt_dict_cursor_new(const xbt_dict_t dict);
XBT_PUBLIC(void) xbt_dict_cursor_free(xbt_dict_cursor_t * cursor);
#include "xbt/mallocator.h"
extern xbt_mallocator_t gras_msg_ctx_mallocator;
void *gras_msg_ctx_mallocator_new_f(void);
-void gras_msg_ctx_mallocator_free_f(void *dict);
+#define gras_msg_ctx_mallocator_free_f xbt_free_f
void gras_msg_ctx_mallocator_reset_f(void *dict);
return xbt_new0(s_gras_msg_cb_ctx_t, 1);
}
-void gras_msg_ctx_mallocator_free_f(void *ctx)
-{
- xbt_free(ctx);
-}
-
void gras_msg_ctx_mallocator_reset_f(void *ctx)
{
memset(ctx, 0, sizeof(s_gras_msg_cb_ctx_t));
unsigned int iter;
char *host_name;
- char buf[16];
- char *buf_copy;
+ char *buf;
parent->is_lowest = 1;
xbt_dynar_free(&parent->container_children);
xbt_dynar_sort (host_names, &compare_hostnames);
xbt_dynar_foreach(host_names, iter, host_name) {
- buf_copy = strdup(buf);
- sprintf(buf_copy, "%d", parent->last_id);
+ buf = bprintf("%d", parent->last_id);
(parent->last_id)++;
- xbt_dict_set(parent->name2id, host_name, buf_copy, NULL);
+ xbt_dict_set(parent->name2id, host_name, buf, xbt_free);
xbt_dict_set(host2_simgrid_parent_container, host_name, parent, NULL);
xbt_dynar_push(parent->resource_list, &host_name);
}
#include "xbt/dynar.h"
#include "surf/surf_private.h"
+#include "surf/surf_resource.h"
#include "surf/surf.h"
#include "instr/jedule/jedule_sd_binding.h"
CHECK_HOST();
#ifdef HAVE_TRACING
TRACE_msg_task_get_start();
- double start_time = MSG_get_clock();
+ volatile double start_time = MSG_get_clock();
#endif
/* Sanity check */
m_channel_t put_channel; /* used for debugging purposes */
smx_action_t waiting_action;
m_task_t waiting_task;
- int argc; /* arguments number if any */
char **argv; /* arguments table if any */
+ int argc; /* arguments number if any */
MSG_error_t last_errno; /* the last value returned by a MSG_function */
void* data; /* user data */
} s_simdata_process_t, *simdata_process_t;
SD_link_t __SD_link_create(void *surf_link, void *data);
-void __SD_link_destroy(void *link);
+#define __SD_link_destroy xbt_free_f
SD_workstation_t __SD_workstation_create(void *surf_workstation,
void *data);
{
return link->sharing_policy;
}
-
-
-/* Destroys a link.
- */
-void __SD_link_destroy(void *link)
-{
- /* link->surf_link is freed by surf_exit and link->data is freed by the user */
- xbt_free(link);
-}
s_surf_resource_t generic_resource;
double power_peak;
double power_scale;
- int core;
tmgr_trace_event_t power_event;
+ int core;
e_surf_resource_state_t state_current;
tmgr_trace_event_t state_event;
lmm_constraint_t constraint;
static void *lmm_variable_mallocator_new_f(void);
static void lmm_variable_mallocator_free_f(void *var);
-static void lmm_variable_mallocator_reset_f(void *var);
+#define lmm_variable_mallocator_reset_f ((void_f_pvoid_t)NULL)
static void lmm_update_modified_set(lmm_system_t sys,
lmm_constraint_t cnst);
static void lmm_remove_all_modified_set(lmm_system_t sys);
xbt_free(var);
}
-static void lmm_variable_mallocator_reset_f(void *var)
-{
- /* lmm_variable_new() initializes everything */
-}
-
lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
double weight,
double bound, int number_of_constraints)
double lambda;
double new_lambda;
double remaining;
- int shared;
double usage;
void *id;
int id_int;
+ int shared;
} s_lmm_constraint_t;
typedef struct lmm_variable {
surfxml_add_callback(ETag_surfxml_platform_cb_list, &parse_ns3_end_platform); //InitializeRoutes
}
-static void free_ns3_elmts(void * elmts)
-{
-}
-
static void free_ns3_link(void * elmts)
{
ns3_link_t link = elmts;
static xbt_mallocator_t action_mallocator = NULL;
static int action_mallocator_allocated_size = 0;
static void* surf_action_mallocator_new_f(void);
-static void surf_action_mallocator_free_f(void* action);
+#define surf_action_mallocator_free_f xbt_free_f
static void surf_action_mallocator_reset_f(void* action);
/**
return xbt_malloc(action_mallocator_allocated_size);
}
-static void surf_action_mallocator_free_f(void* action) {
- xbt_free(action);
-}
-
static void surf_action_mallocator_reset_f(void* action) {
memset(action, 0, action_mallocator_allocated_size);
}
AS_t root;
void *loopback;
size_t size_of_link;
+ xbt_dynar_t last_route;
xbt_dynar_t(*get_onelink_routes) (void);
};
void routing_get_route_and_latency(const char *src, const char *dst,
xbt_dynar_t * route, double *latency)
{
- static xbt_dynar_t last_route = NULL;
-
- int need_cleanup = !(*route);
-
- if (need_cleanup) {
- xbt_dynar_free(&last_route);
- last_route = *route = xbt_dynar_new(global_routing->size_of_link,NULL);
+ if (!*route) {
+ xbt_dynar_reset(global_routing->last_route);
+ *route = global_routing->last_route;
}
_get_route_and_latency(src, dst, route, latency);
global_routing->get_onelink_routes = get_onelink_routes;
global_routing->loopback = loopback;
global_routing->size_of_link = size_of_links;
+ global_routing->last_route = xbt_dynar_new(global_routing->size_of_link,NULL);
/* no current routing at moment */
current_routing = NULL;
}
void routing_exit(void) {
if (!global_routing)
return;
+ xbt_dynar_free(&global_routing->last_route);
finalize_rec(global_routing->root);
xbt_free(global_routing);
}
if (asg->hierarchy == SURF_ROUTING_RECURSIVE && !first
&& strcmp(gw_dst, prev_gw_src)) {
- xbt_dynar_t e_route_as_to_as=NULL;
+ xbt_dynar_t e_route_as_to_as;
+ e_route_as_to_as = xbt_dynar_new(global_routing->size_of_link, NULL);
routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL);
links = e_route_as_to_as;
int pos = 0;
*lat += surf_network_model->extension.network.get_link_latency(link);
pos++;
}
+ xbt_dynar_free(&e_route_as_to_as);
}
links = e_route->link_list;
xbt_dict_free(&as->generic_routing.bypassRoutes);
/* Delete index dict */
xbt_dict_free(&(as->generic_routing.to_index));
- /* Delete dictionary index dict, predecessor and links table */
+ /* Delete predecessor and cost table */
xbt_free(as->predecessor_table);
+ xbt_free(as->cost_table);
model_generic_finalize(rc);
}
{
if(route->dst_gateway && route->src_gateway)
{
- char *gw_src = xbt_strdup(route->src_gateway);
- char *gw_dst = xbt_strdup(route->dst_gateway);
+ char *gw_src = route->src_gateway;
+ char *gw_dst = route->dst_gateway;
route->src_gateway = gw_dst;
route->dst_gateway = gw_src;
}
double power_scale;
double power_current;
tmgr_trace_event_t power_event;
- e_surf_resource_state_t state_current;
tmgr_trace_event_t state_event;
+ e_surf_resource_state_t state_current;
int id; /* cpu and network card are a single object... */
} s_cpu_L07_t, *cpu_L07_t;
link->properties);
xbt_free(link_id);
link_id = bprintf("%s_DOWN", link->id);
- ptask_link_create_resource(bprintf("%s_DOWN", link->id),
+ ptask_link_create_resource(link_id,
link->bandwidth,
link->bandwidth_trace,
link->latency,
static xbt_mallocator_t dict_mallocator = NULL;
static void *dict_mallocator_new_f(void);
-static void dict_mallocator_free_f(void *dict);
-static void dict_mallocator_reset_f(void *dict);
+#define dict_mallocator_free_f xbt_free_f
+#define dict_mallocator_reset_f ((void_f_pvoid_t)NULL)
/*####[ Code ]###############################################################*/
/**
* \brief Constructor
* \return pointer to the destination
- * \see xbt_dict_new_ext(), xbt_dict_free()
+ * \see xbt_dict_free()
*
* Creates and initialize a new dictionary with a default hashtable size.
*/
return xbt_new(s_xbt_dict_t, 1);
}
-static void dict_mallocator_free_f(void *dict)
-{
- xbt_free(dict);
-}
-
-static void dict_mallocator_reset_f(void *dict)
-{
- /* nothing to do because all fields are
- * initialized in xbt_dict_new
- */
-}
-
#ifdef SIMGRID_TEST
#include "xbt.h"
#include "xbt/ex.h"
/* To traverse (simple) dicts */
/* Don't add or remove entries to the dict while traversing !!! */
/*###########################################################################*/
-struct xbt_dict_cursor_ {
+struct s_xbt_dict_cursor {
xbt_dictelm_t current;
int line;
xbt_dict_t dict;
{
return xbt_new(s_xbt_dictelm_t, 1);
}
-
-void dict_elm_mallocator_free_f(void *elem)
-{
- xbt_free(elem);
-}
-
-void dict_elm_mallocator_reset_f(void *elem)
-{
-
-}
#include "xbt/dict.h"
#include "xbt/mallocator.h"
-typedef struct xbt_dictelm_ *xbt_dictelm_t;
+typedef struct s_xbt_dictelm *xbt_dictelm_t;
#define MAX_FILL_PERCENT 80
-typedef struct xbt_dictelm_ {
+typedef struct s_xbt_dictelm {
int dictielem:1;
char *key;
int key_len;
xbt_dictelm_t next;
} s_xbt_dictelm_t;
-typedef struct xbt_dict_ {
+typedef struct s_xbt_dict {
xbt_dictelm_t *table;
int table_size;
int count;
int fill;
} s_xbt_dict_t;
-typedef struct xbt_dict_cursor_ s_xbt_dict_cursor_t;
+typedef struct s_xbt_dict_cursor s_xbt_dict_cursor_t;
extern xbt_mallocator_t dict_elm_mallocator;
extern void *dict_elm_mallocator_new_f(void);
-extern void dict_elm_mallocator_free_f(void *elem);
-extern void dict_elm_mallocator_reset_f(void *elem);
+#define dict_elm_mallocator_free_f xbt_free_f
+#define dict_elm_mallocator_reset_f ((void_f_pvoid_t)NULL)
/*####[ Function prototypes ]################################################*/
xbt_dictelm_t xbt_dictelm_new(const char *key, int key_len,
xbt_dictelm_t xbt_dictielm_new(uintptr_t key, unsigned int hash_code,
uintptr_t content);
void xbt_dictelm_free(xbt_dictelm_t element);
-void xbt_dict_add_element(xbt_dict_t dict, xbt_dictelm_t element);
#endif /* _XBT_DICT_PRIVATE_H_ */
/* 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. */
-#include "portable.h" /* SIZEOF_MAX */
#include "xbt/misc.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
static void _dynar_map(const xbt_dynar_t dynar, void_f_pvoid_t const op);
static XBT_INLINE
- void _xbt_clear_mem(void *const ptr, const unsigned long length)
+void _xbt_dynar_resize(xbt_dynar_t dynar, unsigned long new_size)
{
- memset(ptr, 0, length);
+ if (new_size != dynar->size) {
+ dynar->size = new_size;
+ dynar->data = xbt_realloc(dynar->data, new_size * dynar->elmsize);
+ }
}
static XBT_INLINE
const unsigned long old_size = dynar->size;
if (nb > old_size) {
- void *const old_data = dynar->data;
- const unsigned long elmsize = dynar->elmsize;
- const unsigned long old_length = old_size * elmsize;
-
const unsigned long expand = 2 * (old_size + 1);
- const unsigned long new_size = (nb > expand ? nb : expand);
- const unsigned long new_length = new_size * elmsize;
- void *const new_data = xbt_realloc(old_data, new_length);
-
- XBT_DEBUG("expand %p from %lu to %lu elements", dynar, old_size, new_size);
-
- _xbt_clear_mem((char *)new_data + old_length, new_length - old_length);
-
- dynar->size = new_size;
- dynar->data = new_data;
+ _xbt_dynar_resize(dynar, (nb > expand ? nb : expand));
+ XBT_DEBUG("expand %p from %lu to %lu elements",
+ dynar, old_size, dynar->size);
}
}
if (object) {
_xbt_dynar_get_elm(object, dynar, idx);
} else if (dynar->free_f) {
- if (dynar->elmsize <= SIZEOF_MAX) {
- char elm[SIZEOF_MAX];
- _xbt_dynar_get_elm(elm, dynar, idx);
- dynar->free_f(elm);
- } else {
- char *elm = malloc(dynar->elmsize);
- _xbt_dynar_get_elm(elm, dynar, idx);
- dynar->free_f(elm);
- free(elm);
- }
+ dynar->free_f(_xbt_dynar_elm(dynar, idx));
}
nb_shift = dynar->used - 1 - idx;
void xbt_dynar_free_container(xbt_dynar_t * dynar)
{
if (dynar && *dynar) {
-
- if ((*dynar)->data) {
- _xbt_clear_mem((*dynar)->data, (*dynar)->size);
- free((*dynar)->data);
- }
-
- if ((*dynar)->mutex)
- xbt_mutex_destroy((*dynar)->mutex);
-
- _xbt_clear_mem(*dynar, sizeof(s_xbt_dynar_t));
-
- free(*dynar);
+ xbt_dynar_t d = *dynar;
+ free(d->data);
+ if (d->mutex)
+ xbt_mutex_destroy(d->mutex);
+ free(d);
*dynar = NULL;
}
}
if (dynar->free_f) {
_dynar_map(dynar, dynar->free_f);
}
- /*
- free(dynar->data);
-
- dynar->size = 0;
- */
dynar->used = 0;
_dynar_unlock(dynar);
-
- /* dynar->data = NULL; */
}
/**
*/
void xbt_dynar_shrink(xbt_dynar_t dynar, int empty_slots_wanted)
{
- unsigned long size_wanted;
-
_dynar_lock(dynar);
-
- size_wanted = dynar->used + empty_slots_wanted;
- if (size_wanted != dynar->size) {
- dynar->size = size_wanted;
- dynar->data = xbt_realloc(dynar->data, dynar->elmsize * dynar->size);
- }
+ _xbt_dynar_resize(dynar, dynar->used + empty_slots_wanted);
_dynar_unlock(dynar);
}
return res;
}
-XBT_INLINE void *xbt_dynar_set_at_ptr(const xbt_dynar_t dynar,
- const unsigned long idx)
+/* not synchronized */
+static XBT_INLINE void *_xbt_dynar_set_at_ptr(const xbt_dynar_t dynar,
+ const unsigned long idx)
{
-
- void *res;
- _dynar_lock(dynar);
_sanity_check_dynar(dynar);
- _xbt_dynar_expand(dynar, idx + 1);
-
if (idx >= dynar->used) {
- _xbt_clear_mem(((char * const)dynar->data) + dynar->used * dynar->elmsize,
- (idx + 1 - dynar->used)*dynar->elmsize);
+ _xbt_dynar_expand(dynar, idx + 1);
+ if (idx > dynar->used) {
+ memset(_xbt_dynar_elm(dynar, dynar->used), 0,
+ (idx - dynar->used) * dynar->elmsize);
+ }
dynar->used = idx + 1;
}
-
- _dynar_unlock(dynar);
-
- res = _xbt_dynar_elm(dynar, idx);
+ return _xbt_dynar_elm(dynar, idx);
+}
+XBT_INLINE void *xbt_dynar_set_at_ptr(const xbt_dynar_t dynar,
+ const unsigned long idx)
+{
+ void *res;
+ _dynar_lock(dynar);
+ res = _xbt_dynar_set_at_ptr(dynar, idx);
+ _dynar_unlock(dynar);
return res;
}
_xbt_dynar_set(xbt_dynar_t dynar,
const unsigned long idx, const void *const src)
{
-
- _sanity_check_dynar(dynar);
-
- _xbt_dynar_expand(dynar, idx + 1);
-
- if (idx >= dynar->used) {
- _xbt_clear_mem(((char * const)dynar->data) + dynar->used * dynar->elmsize,
- (idx + 1 - dynar->used)*dynar->elmsize);
- dynar->used = idx + 1;
- }
-
- _xbt_dynar_put_elm(dynar, idx, src);
+ memcpy(_xbt_dynar_set_at_ptr(dynar, idx), src, dynar->elmsize);
}
/** @brief Set the Nth element of a dynar (expanded if needed). Previous value at this position is NOT freed
*/
XBT_INLINE void * xbt_dynar_to_array (xbt_dynar_t dynar)
{
- void * res;
- void * last = xbt_new0(char,dynar->elmsize);
- xbt_dynar_push(dynar, last);
- free(last);
- res = dynar->data;
- free(dynar);
- return res;
+ void *res;
+ xbt_dynar_shrink(dynar, 1);
+ memset(xbt_dynar_push_ptr(dynar), 0, dynar->elmsize);
+ res = dynar->data;
+ if (dynar->mutex)
+ xbt_mutex_destroy(dynar->mutex);
+ free(dynar);
+ return res;
}
/*
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_fifo, xbt, "FIFO");
static void *fifo_item_mallocator_new_f(void);
-static void fifo_item_mallocator_free_f(void *item);
+#define fifo_item_mallocator_free_f xbt_free_f
static void fifo_item_mallocator_reset_f(void *item);
static xbt_mallocator_t item_mallocator = NULL;
return xbt_new(s_xbt_fifo_item_t, 1);
}
-static void fifo_item_mallocator_free_f(void *item)
-{
- xbt_free(item);
-}
-
static void fifo_item_mallocator_reset_f(void *item)
{
/* memset to zero like calloc */
typedef struct {
char *catname;
- e_xbt_log_priority_t thresh;
char *fmt;
+ e_xbt_log_priority_t thresh;
int additivity;
xbt_log_appender_t appender;
} s_xbt_log_setting_t, *xbt_log_setting_t;
* in \a xbt_mallocator_release() when the stack is full, and when
* the mallocator is freed.
* \param reset_f function to reinitialise an object of your datatype, called
- * when you extract an object from the mallocator
+ * when you extract an object from the mallocator (can be NULL)
*
* Create and initialize a new mallocator for a given datatype.
*
xbt_mallocator_t m;
xbt_assert(size > 0, "size must be positive");
- xbt_assert(new_f != NULL && free_f != NULL
- && reset_f != NULL, "invalid parameter");
+ xbt_assert(new_f != NULL && free_f != NULL, "invalid parameter");
m = xbt_new0(s_xbt_mallocator_t, 1);
XBT_VERB("Create mallocator %p", m);
* If the mallocator is empty, a new object is created,
* by calling the function new_f().
*
- * In both cases, the function reset_f() is called on the object.
+ * In both cases, the function reset_f() (if defined) is called on the object.
*
* \see xbt_mallocator_release()
*/
object = m->new_f();
}
- m->reset_f(object);
+ if (m->reset_f)
+ m->reset_f(object);
return object;
}
#define _XBT_MALLOCATOR_PRIVATE_H__
typedef struct s_xbt_mallocator {
- int current_size; /* number of objects currently stored */
void **objects; /* objects stored by the mallocator and available for the user */
+ int current_size; /* number of objects currently stored */
int max_size; /* maximum number of objects */
pvoid_f_void_t new_f; /* function to call when we are running out of objects */
void_f_pvoid_t free_f; /* function to call when we have got too many objects */
*
* \param set set to populate
* \param elm element to add.
- * \param free_func How to add the data
+ * \param free_func how to free the data
*
* elm->name must be set;
* if elm->name_len <= 0, it is recomputed. If >0, it's used as is;
int res = strncmp(s1, s2, sort_len);
if (res == 0)
- return p1>p2;
+ res = p1 > p2 ? 1 : (p1 < p2 ? -1 : 0);
return res;
}