Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into mc-process
[simgrid.git] / src / simix / smx_global.c
index 317ea15..0011f97 100644 (file)
@@ -4,6 +4,8 @@
 /* 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 <stdlib.h>
+
 #include "smx_private.h"
 #include "xbt/heap.h"
 #include "xbt/sysdep.h"
@@ -15,6 +17,9 @@
 
 #ifdef HAVE_MC
 #include "mc/mc_private.h"
+#include "mc/mc_model_checker.h"
+#include "mc/mc_protocol.h"
+#include "mc/mc_client.h"
 #endif
 #include "mc/mc_record.h"
 
@@ -206,6 +211,21 @@ void SIMIX_global_init(int *argc, char **argv)
   if (sg_cfg_get_boolean("clean_atexit"))
     atexit(SIMIX_clean);
 
+#ifdef HAVE_MC
+  // The communication initialisation is done ASAP.
+  // We need to commuicate  initialisation of the different layers to the model-checker.
+  if (mc_mode == MC_MODE_NONE) {
+    if (getenv(MC_ENV_SOCKET_FD)) {
+      mc_mode = MC_MODE_CLIENT;
+      MC_client_init();
+      MC_client_hello();
+      MC_client_handle_messages();
+    } else {
+      mc_mode = MC_MODE_STANDALONE;
+    }
+  }
+#endif
+
   if (_sg_cfg_exit_asap)
     exit(0);
 }
@@ -404,6 +424,22 @@ void SIMIX_run(void)
           SIMIX_simcall_handle(&process->simcall, 0);
         }
       }
+      /* Wake up all processes waiting for a Surf action to finish */
+      xbt_dynar_foreach(model_list, iter, model) {
+        XBT_DEBUG("Handling process whose action failed");
+        while ((action = surf_model_extract_failed_action_set(model))) {
+          XBT_DEBUG("   Handling Action %p",action);
+          SIMIX_simcall_exit((smx_synchro_t) surf_action_get_data(action));
+        }
+        XBT_DEBUG("Handling process whose action terminated normally");
+        while ((action = surf_model_extract_done_action_set(model))) {
+          XBT_DEBUG("   Handling Action %p",action);
+          if (surf_action_get_data(action) == NULL)
+            XBT_DEBUG("probably vcpu's action %p, skip", action);
+          else
+            SIMIX_simcall_exit((smx_synchro_t) surf_action_get_data(action));
+        }
+      }
     }
 
     time = SIMIX_timer_next();