/* Process creation/destruction callbacks */
typedef void (*void_pfn_smxprocess_t) (smx_process_t);
-/* Process kill */
-typedef void (*void_pfn_smxprocess_t_smxprocess_t) (smx_process_t, smx_process_t);
/* for auto-restart function */
typedef void (*void_pfn_sghost_t) (sg_host_t);
XBT_PUBLIC(void) SIMIX_function_register_process_cleanup(void_pfn_smxprocess_t function);
XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function);
-XBT_PUBLIC(void) SIMIX_function_register_process_kill(void_pfn_smxprocess_t_smxprocess_t function);
+XBT_PUBLIC(void) SIMIX_function_register_process_kill(void_pfn_smxprocess_t function);
/* Simulation execution */
XBT_PUBLIC(void) SIMIX_run(void);
/* Timer functions FIXME: should these be public? */
typedef struct s_smx_timer* smx_timer_t;
-XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, void *function, void *arg);
+XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, void (*function)(void*), void *arg);
XBT_PUBLIC(void) SIMIX_timer_remove(smx_timer_t timer);
XBT_PUBLIC(double) SIMIX_timer_next(void);
XBT_PUBLIC(double) SIMIX_timer_get_date(smx_timer_t timer);
}
}
+static void kill_process(void* arg)
+{
+ simix_global->kill_process_function((smx_process_t) arg);
+}
+
/**
* \ingroup simix_process_management
* \brief Set the kill time of a process.
if (simix_global->kill_process_function) {
XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
sg_host_get_name(process->host));
- process->kill_timer = SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
+ process->kill_timer = SIMIX_timer_set(kill_time, kill_process, process);
}
}
}
smx_global_t simix_global = NULL;
static xbt_heap_t simix_timers = NULL;
+/** @brief Timer datatype */
+typedef struct s_smx_timer {
+ double date;
+ void(* func)(void*);
+ void* args;
+} s_smx_timer_t;
+
static void* SIMIX_synchro_mallocator_new_f(void);
static void SIMIX_synchro_mallocator_free_f(void* synchro);
static void SIMIX_synchro_mallocator_reset_f(void* synchro);
return xbt_heap_size(simix_timers) > 0 ? xbt_heap_maxkey(simix_timers) : -1.0;
}
+static void kill_process(smx_process_t process)
+{
+ SIMIX_process_kill(process, NULL);
+}
+
/**
* \ingroup SIMIX_API
* \brief Initialize SIMIX internal data.
simix_global->registered_functions = xbt_dict_new_homogeneous(NULL);
simix_global->create_process_function = SIMIX_process_create;
- simix_global->kill_process_function = SIMIX_process_kill;
+ simix_global->kill_process_function = kill_process;
simix_global->cleanup_process_function = SIMIX_process_cleanup;
simix_global->synchro_mallocator = xbt_mallocator_new(65536,
SIMIX_synchro_mallocator_new_f, SIMIX_synchro_mallocator_free_f,
// (i.e. provide dispatchers that read and expand the args)
timer = xbt_heap_pop(simix_timers);
if (timer->func)
- ((void (*)(void*))timer->func)(timer->args);
+ timer->func(timer->args);
xbt_free(timer);
}
* \param arg Parameters of the function
*
*/
-XBT_INLINE smx_timer_t SIMIX_timer_set(double date, void *function, void *arg)
+XBT_INLINE smx_timer_t SIMIX_timer_set(double date, void (*function)(void*), void *arg)
{
smx_timer_t timer = xbt_new0(s_smx_timer_t, 1);
*
* \param function Kill process function
*/
-XBT_INLINE void SIMIX_function_register_process_kill(void_pfn_smxprocess_t_smxprocess_t
+XBT_INLINE void SIMIX_function_register_process_kill(void_pfn_smxprocess_t
function)
{
simix_global->kill_process_function = function;
smx_process_t maestro_process;
xbt_dict_t registered_functions;
smx_creation_func_t create_process_function;
- void_pfn_smxprocess_t_smxprocess_t kill_process_function;
+ void_pfn_smxprocess_t kill_process_function;
/** Callback used when killing a SMX_process */
void_pfn_smxprocess_t cleanup_process_function;
xbt_mallocator_t synchro_mallocator;
void* data; /**< @brief user data */
} s_smx_file_t;
-/*********************************** Time ************************************/
-
-/** @brief Timer datatype */
-typedef struct s_smx_timer {
- double date;
- void* func;
- void* args;
-} s_smx_timer_t;
-
/********************************* synchro *************************************/
typedef enum {
XBT_DEBUG("Process %s(%s) will be started at time %f", arg->name,
arg->hostname, start_time);
- SIMIX_timer_set(start_time, (void*) SIMIX_process_create_from_wrapper, arg);
+ SIMIX_timer_set(start_time, [](void* arg) {
+ SIMIX_process_create_from_wrapper((smx_process_arg_t) arg);
+ }, arg);
} else { // start_time <= SIMIX_get_clock()
XBT_DEBUG("Starting Process %s(%s) right now", process->argv[0], sg_host_get_name(host));