+ s_smx_process_t proc;
+
+ if (!simix_global) {
+ /* Connect our log channels: that must be done manually under windows */
+ XBT_LOG_CONNECT(simix_action, simix);
+ XBT_LOG_CONNECT(simix_deployment, simix);
+ XBT_LOG_CONNECT(simix_environment, simix);
+ XBT_LOG_CONNECT(simix_host, simix);
+ XBT_LOG_CONNECT(simix_kernel, simix);
+ XBT_LOG_CONNECT(simix_process, simix);
+ XBT_LOG_CONNECT(simix_synchro, simix);
+ XBT_LOG_CONNECT(simix_context, simix);
+
+ simix_global = xbt_new0(s_smx_global_t, 1);
+
+ simix_global->process_to_run = xbt_dynar_new(sizeof(smx_process_t), NULL);
+ simix_global->process_that_ran = xbt_dynar_new(sizeof(smx_process_t), NULL);
+ simix_global->process_list =
+ xbt_swag_new(xbt_swag_offset(proc, process_hookup));
+ simix_global->process_to_destroy =
+ xbt_swag_new(xbt_swag_offset(proc, destroy_hookup));
+
+ simix_global->maestro_process = NULL;
+ simix_global->registered_functions = xbt_dict_new();
+
+ simix_global->create_process_function = SIMIX_process_create;
+ simix_global->kill_process_function = SIMIX_process_kill;
+ 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();
+ SIMIX_create_maestro_process();
+
+ /* context exception handlers */
+ __xbt_running_ctx_fetch = SIMIX_process_get_running_context;
+ __xbt_ex_terminate = SIMIX_process_exception_terminate;
+
+ /* Initialize the SIMIX network module */
+ SIMIX_network_init();
+
+ /* Prepare to display some more info when dying on Ctrl-C pressing */
+ signal(SIGINT, inthandler);
+ }
+ if (!simix_timers) {
+ simix_timers = xbt_heap_new(8, &free);
+ }
+
+ XBT_DEBUG("ADD SIMIX LEVELS");
+ SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy);
+}
+
+/**
+ * \brief Clean the SIMIX simulation
+ *
+ * This functions remove the memory used by SIMIX
+ */
+void SIMIX_clean(void)
+{
+#ifdef TIME_BENCH
+ smx_ctx_raw_new_sr();
+#endif
+
+ /* Kill everyone (except maestro) */
+ SIMIX_process_killall(simix_global->maestro_process);
+
+ /* Exit the SIMIX network module */
+ SIMIX_network_exit();
+
+ xbt_heap_free(simix_timers);
+ /* Free the remaining data structures */
+ xbt_dynar_free(&simix_global->process_to_run);
+ xbt_dynar_free(&simix_global->process_that_ran);
+ xbt_swag_free(simix_global->process_to_destroy);
+ xbt_swag_free(simix_global->process_list);
+ simix_global->process_list = NULL;
+ simix_global->process_to_destroy = NULL;
+ xbt_dict_free(&(simix_global->registered_functions));
+
+ /* Let's free maestro now */
+ SIMIX_context_free(simix_global->maestro_process->context);
+ xbt_free(simix_global->maestro_process->running_ctx);
+ xbt_free(simix_global->maestro_process);
+ simix_global->maestro_process = NULL;
+
+ /* Restore the default exception setup */
+ __xbt_running_ctx_fetch = &__xbt_ex_ctx_default;
+ __xbt_ex_terminate = &__xbt_ex_terminate_default;