Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Remove ugly #include
[simgrid.git] / src / mc / mc_server.cpp
index 92c0e2e..ba80984 100644 (file)
@@ -21,6 +21,7 @@
 #include "mc_private.h"
 #include "mc_ignore.h"
 #include "mcer_ignore.h"
+#include "mc_exit.h"
 
 using simgrid::mc::remote;
 
@@ -95,21 +96,21 @@ void s_mc_server::shutdown()
   XBT_DEBUG("Shuting down model-checker");
 
   mc_process_t process = &mc_model_checker->process();
-  int status = process->status;
-  if (process->running) {
+  int status = process->status();
+  if (process->running()) {
     XBT_DEBUG("Killing process");
     kill(process->pid(), SIGTERM);
     if (waitpid(process->pid(), &status, 0) == -1)
       throw std::system_error(errno, std::system_category());
     // TODO, handle the case when the process does not want to die with a timeout
-    process->status = status;
+    process->terminate(status);
   }
 }
 
 void s_mc_server::exit()
 {
   // Finished:
-  int status = mc_model_checker->process().status;
+  int status = mc_model_checker->process().status();
   if (WIFEXITED(status))
     ::exit(WEXITSTATUS(status));
   else if (WIFSIGNALED(status)) {
@@ -124,8 +125,7 @@ void s_mc_server::exit()
 
 void s_mc_server::resume(mc_process_t process)
 {
-  int socket = process->socket;
-  int res = MC_protocol_send_simple_message(socket, MC_MESSAGE_CONTINUE);
+  int res = process->send_message(MC_MESSAGE_CONTINUE);
   if (res)
     throw std::system_error(res, std::system_category());
   process->cache_flags = (mc_process_cache_flags_t) 0;
@@ -239,7 +239,7 @@ bool s_mc_server::handle_events()
 
       case MC_MESSAGE_ASSERTION_FAILED:
         MC_report_assertion_error();
-        xbt_abort();
+        ::exit(SIMGRID_EXIT_SAFETY);
         break;
 
       default:
@@ -272,7 +272,7 @@ bool s_mc_server::handle_events()
 
 void s_mc_server::loop()
 {
-  while (mc_model_checker->process().running)
+  while (mc_model_checker->process().running())
     this->handle_events();
 }
 
@@ -305,7 +305,7 @@ void s_mc_server::handle_waitpid()
     if (pid == -1) {
       if (errno == ECHILD) {
         // No more children:
-        if (mc_model_checker->process().running)
+        if (mc_model_checker->process().running())
           xbt_die("Inconsistent state");
         else
           break;
@@ -318,8 +318,7 @@ void s_mc_server::handle_waitpid()
     if (pid == mc_model_checker->process().pid()) {
       if (WIFEXITED(status) || WIFSIGNALED(status)) {
         XBT_DEBUG("Child process is over");
-        mc_model_checker->process().status = status;
-        mc_model_checker->process().running = false;
+        mc_model_checker->process().terminate(status);
       }
     }
   }
@@ -339,7 +338,7 @@ void s_mc_server::on_signal(const struct signalfd_siginfo* info)
 void MC_server_wait_client(mc_process_t process)
 {
   mc_server->resume(process);
-  while (mc_model_checker->process().running) {
+  while (mc_model_checker->process().running()) {
     if (!mc_server->handle_events())
       return;
   }
@@ -352,9 +351,9 @@ void MC_server_simcall_handle(mc_process_t process, unsigned long pid, int value
   m.type  = MC_MESSAGE_SIMCALL_HANDLE;
   m.pid   = pid;
   m.value = value;
-  MC_protocol_send(mc_model_checker->process().socket, &m, sizeof(m));
+  mc_model_checker->process().send_message(m);
   process->cache_flags = (mc_process_cache_flags_t) 0;
-  while (mc_model_checker->process().running) {
+  while (mc_model_checker->process().running()) {
     if (!mc_server->handle_events())
       return;
   }