XBT_PUBLIC(xbt_fifo_t) xbt_fifo_new(void);
XBT_PUBLIC(void) xbt_fifo_free(xbt_fifo_t);
+XBT_PUBLIC(void) xbt_fifo_reset(xbt_fifo_t);
/** @} */
/** @defgroup XBT_fifo_perl Fifo perl-like functions
#include "xbt/fifo.h"
#include "xbt/swag.h"
#include "xbt/dict.h"
+#include "xbt/mallocator.h"
#include "xbt/config.h"
#include "xbt/function_types.h"
#include "xbt/ex_interface.h"
smx_creation_func_t create_process_function;
void_f_pvoid_t kill_process_function;
void_pfn_smxprocess_t cleanup_process_function;
+ xbt_mallocator_t action_mallocator;
} s_smx_global_t, *smx_global_t;
extern smx_global_t simix_global;
smx_global_t simix_global = NULL;
static xbt_heap_t simix_timers = NULL;
+static void* SIMIX_action_mallocator_new_f(void);
+static void SIMIX_action_mallocator_free_f(void* action);
+static void SIMIX_action_mallocator_reset_f(void* action);
+
/* FIXME: Yeah, I'll do it in a portable maner one day [Mt] */
#include <signal.h>
simix_global->create_process_function = NULL;
simix_global->kill_process_function = NULL;
simix_global->cleanup_process_function = SIMIX_process_cleanup;
+ simix_global->action_mallocator = xbt_mallocator_new(65536,
+ SIMIX_action_mallocator_new_f, SIMIX_action_mallocator_free_f,
+ SIMIX_action_mallocator_reset_f);
surf_init(argc, argv); /* Initialize SURF structures */
SIMIX_context_mod_init();
}
}
}
+
+static void* SIMIX_action_mallocator_new_f(void) {
+ smx_action_t action = xbt_new(s_smx_action_t, 1);
+ action->request_list = xbt_fifo_new();
+ return action;
+}
+
+static void SIMIX_action_mallocator_free_f(void* action) {
+ xbt_fifo_free(((smx_action_t) action)->request_list);
+ xbt_free(action);
+}
+
+static void SIMIX_action_mallocator_reset_f(void* action) {
+
+ // we also recycle the request list
+ xbt_fifo_t fifo = ((smx_action_t) action)->request_list;
+ xbt_fifo_reset(fifo);
+ memset(action, 0, sizeof(s_smx_action_t));
+ ((smx_action_t) action)->request_list = fifo;
+}
double priority)
{
/* alloc structures and initialize */
- smx_action_t action = xbt_new0(s_smx_action_t, 1);
+ smx_action_t action = xbt_mallocator_get(simix_global->action_mallocator);
action->type = SIMIX_ACTION_EXECUTE;
action->name = xbt_strdup(name);
- action->request_list = xbt_fifo_new();
action->state = SIMIX_RUNNING;
action->execution.host = host;
int i;
/* alloc structures and initialize */
- smx_action_t action = xbt_new0(s_smx_action_t, 1);
+ smx_action_t action = xbt_mallocator_get(simix_global->action_mallocator);
action->type = SIMIX_ACTION_PARALLEL_EXECUTE;
action->name = xbt_strdup(name);
- action->request_list = xbt_fifo_new();
action->state = SIMIX_RUNNING;
action->execution.host = NULL; /* FIXME: do we need the list of hosts? */
{
DEBUG1("Destroy action %p", action);
- if (action->name)
- xbt_free(action->name);
-
- xbt_fifo_free(action->request_list);
+ xbt_free(action->name);
if (action->execution.surf_exec) {
surf_workstation_model->action_unref(action->execution.surf_exec);
#ifdef HAVE_TRACING
TRACE_smx_action_destroy(action);
#endif
- xbt_free(action);
+ xbt_mallocator_release(simix_global->action_mallocator, action);
}
void SIMIX_host_execution_cancel(smx_action_t action)
smx_action_t act;
/* alloc structures */
- act = xbt_new0(s_smx_action_t, 1);
+ act = xbt_mallocator_get(simix_global->action_mallocator);
act->type = SIMIX_ACTION_COMMUNICATE;
act->state = SIMIX_WAITING;
- act->request_list = xbt_fifo_new();
/* set communication */
act->comm.type = type;
TRACE_smx_action_destroy(action);
#endif
- if (action->name)
- xbt_free(action->name);
-
- xbt_fifo_free(action->request_list);
-
+ xbt_free(action->name);
SIMIX_comm_destroy_internal_actions(action);
if (action->comm.detached && action->state != SIMIX_DONE) {
((void_f_pvoid_t) action->comm.src_data)(action->comm.src_buff);
}
- xbt_free(action);
+ xbt_mallocator_release(simix_global->action_mallocator, action);
}
void SIMIX_comm_destroy_internal_actions(smx_action_t action)
host->name);
}
- action = xbt_new0(s_smx_action_t, 1);
+ action = xbt_mallocator_get(simix_global->action_mallocator);
action->type = SIMIX_ACTION_SLEEP;
- action->request_list = xbt_fifo_new();
action->name = xbt_strdup("sleep");
#ifdef HAVE_TRACING
action->category = NULL;
void SIMIX_process_sleep_destroy(smx_action_t action)
{
DEBUG1("Destroy action %p", action);
- if (action->name)
- xbt_free(action->name);
+ xbt_free(action->name);
if (action->sleep.surf_sleep)
action->sleep.surf_sleep->model_type->action_unref(action->sleep.surf_sleep);
#ifdef HAVE_TRACING
TRACE_smx_action_destroy(action);
#endif
- xbt_fifo_free(action->request_list);
- xbt_free(action);
+ xbt_mallocator_release(simix_global->action_mallocator, action);
}
void SIMIX_process_sleep_suspend(smx_action_t action)
static smx_action_t SIMIX_synchro_wait(smx_host_t smx_host, double timeout)
{
smx_action_t action;
- action = xbt_new0(s_smx_action_t, 1);
+ action = xbt_mallocator_get(simix_global->action_mallocator);
action->type = SIMIX_ACTION_SYNCHRO;
- action->request_list = xbt_fifo_new();
action->name = xbt_strdup("synchro");
action->synchro.sleep =
surf_workstation_model->extension.workstation.sleep(smx_host->host, timeout);
{
DEBUG1("Destroying synchro %p", action);
action->synchro.sleep->model_type->action_unref(action->synchro.sleep);
- xbt_fifo_free(action->request_list);
xbt_free(action->name);
- xbt_free(action);
+ xbt_mallocator_release(simix_global->action_mallocator, action);
}
void SIMIX_post_synchro(smx_action_t action)
/* Surf actions mallocator */
static xbt_mallocator_t action_mallocator = NULL;
static int action_mallocator_allocated_size = 0;
-static void* action_mallocator_new_f(void);
-static void action_mallocator_free_f(void* action);
-static void action_mallocator_reset_f(void* action);
+static void* surf_action_mallocator_new_f(void);
+static void surf_action_mallocator_free_f(void* action);
+static void surf_action_mallocator_reset_f(void* action);
/**
* \brief Initializes the action module of Surf.
* so this size should be set to the maximum size of the surf action structures
*/
action_mallocator_allocated_size = sizeof(s_surf_action_network_CM02_t);
- action_mallocator = xbt_mallocator_new(128, action_mallocator_new_f,
- action_mallocator_free_f, action_mallocator_reset_f);
+ action_mallocator = xbt_mallocator_new(65536, surf_action_mallocator_new_f,
+ surf_action_mallocator_free_f, surf_action_mallocator_reset_f);
}
/**
xbt_mallocator_free(action_mallocator);
}
-static void* action_mallocator_new_f(void) {
- return xbt_malloc0(action_mallocator_allocated_size);
+static void* surf_action_mallocator_new_f(void) {
+ return xbt_malloc(action_mallocator_allocated_size);
}
-static void action_mallocator_free_f(void* action) {
+static void surf_action_mallocator_free_f(void* action) {
xbt_free(action);
}
-static void action_mallocator_reset_f(void* action) {
+static void surf_action_mallocator_reset_f(void* action) {
memset(action, 0, action_mallocator_allocated_size);
}
* Free the fifo structure. None of the objects that was in the fifo is however modified.
*/
void xbt_fifo_free(xbt_fifo_t l)
+{
+ xbt_fifo_reset(l);
+ xbt_free(l);
+}
+
+/**
+ * \brief Makes a fifo empty.
+ * \param l a fifo
+ *
+ * None of the objects that was in the fifo is however modified.
+ */
+void xbt_fifo_reset(xbt_fifo_t l)
{
xbt_fifo_item_t b, tmp;
for (b = xbt_fifo_get_first_item(l); b;
tmp = b, b = b->next, xbt_fifo_free_item(tmp));
- xbt_free(l);
- return;
+ l->head = l->tail = NULL;
}
/** Push