Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use method get() instead of &* for intrusive_ptr.
[simgrid.git] / src / mc / mc_request.cpp
index 1d3b8c6..c07f4ff 100644 (file)
@@ -1,21 +1,14 @@
-/* Copyright (c) 2008-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2008-2017. The SimGrid Team. All rights reserved.          */
 
 /* 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 <cassert>
 
-#include <xbt/log.h>
-#include <xbt/str.h>
-#include <xbt/sysdep.h>
-#include <xbt/dynar.h>
-#include <xbt/swag.h>
-
-#include "src/mc/mc_request.h"
-#include "src/mc/mc_safety.h"
-#include "src/mc/mc_private.h"
-#include "src/mc/mc_smx.h"
+#include "src/include/mc/mc.h"
+#include "src/mc/ModelChecker.hpp"
+#include "src/mc/mc_request.hpp"
+#include "src/mc/mc_smx.hpp"
 #include "src/mc/mc_xbt.hpp"
 
 using simgrid::mc::remote;
@@ -26,14 +19,13 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_request, mc,
 static char *pointer_to_string(void *pointer);
 static char *buff_size_to_string(size_t size);
 
-static inline
-simgrid::kernel::activity::Comm* MC_get_comm(smx_simcall_t r)
+static inline simgrid::kernel::activity::CommImpl* MC_get_comm(smx_simcall_t r)
 {
   switch (r->call ) {
   case SIMCALL_COMM_WAIT:
-    return static_cast<simgrid::kernel::activity::Comm*>(simcall_comm_wait__get__comm(r));
+    return static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_wait__getraw__comm(r));
   case SIMCALL_COMM_TEST:
-    return static_cast<simgrid::kernel::activity::Comm*>(simcall_comm_test__get__comm(r));
+    return static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_test__getraw__comm(r));
   default:
     return nullptr;
   }
@@ -67,8 +59,8 @@ bool request_depend_asymmetric(smx_simcall_t r1, smx_simcall_t r2)
 
   // Those are internal requests, we do not need indirection
   // because those objects are copies:
-  simgrid::kernel::activity::Comm* synchro1 = MC_get_comm(r1);
-  simgrid::kernel::activity::Comm* synchro2 = MC_get_comm(r2);
+  simgrid::kernel::activity::CommImpl* synchro1 = MC_get_comm(r1);
+  simgrid::kernel::activity::CommImpl* synchro2 = MC_get_comm(r2);
 
   if ((r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
       && r2->call == SIMCALL_COMM_WAIT) {
@@ -154,8 +146,8 @@ bool request_depend(smx_simcall_t r1, smx_simcall_t r2)
 
   // Those are internal requests, we do not need indirection
   // because those objects are copies:
-  simgrid::kernel::activity::Comm* synchro1 = MC_get_comm(r1);
-  simgrid::kernel::activity::Comm* synchro2 = MC_get_comm(r2);
+  simgrid::kernel::activity::CommImpl* synchro1 = MC_get_comm(r1);
+  simgrid::kernel::activity::CommImpl* synchro2 = MC_get_comm(r2);
 
   switch(r1->call) {
   case SIMCALL_COMM_ISEND:
@@ -168,16 +160,11 @@ bool request_depend(smx_simcall_t r1, smx_simcall_t r2)
     if (synchro1->src_buff == synchro2->src_buff
         && synchro1->dst_buff == synchro2->dst_buff)
       return false;
-    else if (synchro1->src_buff != nullptr
-        && synchro1->dst_buff != nullptr
-        && synchro2->src_buff != nullptr
-        && synchro2->dst_buff != nullptr
-        && synchro1->dst_buff != synchro2->src_buff
-        && synchro1->dst_buff != synchro2->dst_buff
-        && synchro2->dst_buff != synchro1->src_buff)
+    if (synchro1->src_buff != nullptr && synchro1->dst_buff != nullptr && synchro2->src_buff != nullptr &&
+        synchro2->dst_buff != nullptr && synchro1->dst_buff != synchro2->src_buff &&
+        synchro1->dst_buff != synchro2->dst_buff && synchro2->dst_buff != synchro1->src_buff)
       return false;
-    else
-      return true;
+    return true;
   default:
     return true;
   }
@@ -207,7 +194,7 @@ static char *buff_size_to_string(size_t buff_size)
 
 std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid::mc::RequestType request_type)
 {
-  xbt_assert(mc_model_checker != nullptr);
+  xbt_assert(mc_model_checker != nullptr, "Must be called from MCer");
 
   bool use_remote_comm = true;
   switch(request_type) {
@@ -218,6 +205,8 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid
   case simgrid::mc::RequestType::internal:
     use_remote_comm = false;
     break;
+  default:
+    THROW_IMPOSSIBLE;
   }
 
   const char* type = nullptr;
@@ -243,8 +232,6 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid
 
   case SIMCALL_COMM_IRECV: {
     size_t* remote_size = simcall_comm_irecv__get__dst_buff_size(req);
-
-    // size_t size = size_pointer ? *size_pointer : 0;
     size_t size = 0;
     if (remote_size)
       mc_model_checker->process().read_bytes(&size, sizeof(size),
@@ -264,8 +251,8 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid
   }
 
   case SIMCALL_COMM_WAIT: {
-    simgrid::kernel::activity::Comm* remote_act =
-      static_cast<simgrid::kernel::activity::Comm*>(simcall_comm_wait__get__comm(req));
+    simgrid::kernel::activity::CommImpl* remote_act =
+        static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_wait__getraw__comm(req));
     char* p;
     if (value == -1) {
       type = "WaitTimeout";
@@ -275,11 +262,11 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid
       type = "Wait";
       p = pointer_to_string(remote_act);
 
-      simgrid::mc::Remote<simgrid::kernel::activity::Comm> temp_synchro;
-      simgrid::kernel::activity::Comm* act;
+      simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_synchro;
+      simgrid::kernel::activity::CommImpl* act;
       if (use_remote_comm) {
-        mc_model_checker->process().read(temp_synchro, remote(
-          static_cast<simgrid::kernel::activity::Comm*>(remote_act)));
+        mc_model_checker->process().read(temp_synchro,
+                                         remote(static_cast<simgrid::kernel::activity::CommImpl*>(remote_act)));
         act = temp_synchro.getBuffer();
       } else
         act = remote_act;
@@ -297,13 +284,13 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid
   }
 
   case SIMCALL_COMM_TEST: {
-    simgrid::kernel::activity::Comm* remote_act = static_cast<simgrid::kernel::activity::Comm*>(
-      simcall_comm_test__get__comm(req));
-    simgrid::mc::Remote<simgrid::kernel::activity::Comm> temp_synchro;
-    simgrid::kernel::activity::Comm* act;
+    simgrid::kernel::activity::CommImpl* remote_act =
+        static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_test__getraw__comm(req));
+    simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_synchro;
+    simgrid::kernel::activity::CommImpl* act;
     if (use_remote_comm) {
-      mc_model_checker->process().read(temp_synchro, remote(
-        static_cast<simgrid::kernel::activity::Comm*>(remote_act)));
+      mc_model_checker->process().read(temp_synchro,
+                                       remote(static_cast<simgrid::kernel::activity::CommImpl*>(remote_act)));
       act = temp_synchro.getBuffer();
     } else
       act = remote_act;
@@ -332,12 +319,12 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid
     s_xbt_dynar_t comms;
     mc_model_checker->process().read_bytes(
       &comms, sizeof(comms), remote(simcall_comm_waitany__get__comms(req)));
-    if (!xbt_dynar_is_empty(&comms)) {
+    if (not xbt_dynar_is_empty(&comms)) {
       smx_activity_t remote_sync;
       read_element(mc_model_checker->process(),
         &remote_sync, remote(simcall_comm_waitany__get__comms(req)), value,
         sizeof(remote_sync));
-      char* p = pointer_to_string(remote_sync);
+      char* p = pointer_to_string(remote_sync.get());
       args = bprintf("comm=%s (%d of %lu)",
         p, value + 1, xbt_dynar_length(&comms));
       xbt_free(p);
@@ -365,7 +352,7 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid
     else
       type = "Mutex TRYLOCK";
 
-    simgrid::mc::Remote<simgrid::simix::Mutex> mutex;
+    simgrid::mc::Remote<simgrid::simix::MutexImpl> mutex;
     mc_model_checker->process().read_bytes(mutex.getBuffer(), sizeof(mutex),
       remote(
         req->call == SIMCALL_MUTEX_LOCK
@@ -412,42 +399,33 @@ namespace mc {
 
 bool request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx)
 {
-  smx_activity_t remote_act = nullptr;
+  simgrid::kernel::activity::ActivityImpl* remote_act = nullptr;
   switch (req->call) {
 
   case SIMCALL_COMM_WAIT:
     /* FIXME: check also that src and dst processes are not suspended */
-    remote_act = simcall_comm_wait__get__comm(req);
+    remote_act = simcall_comm_wait__getraw__comm(req);
     break;
 
-  case SIMCALL_COMM_WAITANY: {
-    read_element(
-      mc_model_checker->process(), &remote_act,
-      remote(simcall_comm_waitany__get__comms(req)),
-      idx, sizeof(remote_act));
-    }
+  case SIMCALL_COMM_WAITANY:
+    read_element(mc_model_checker->process(), &remote_act, remote(simcall_comm_waitany__getraw__comms(req)), idx,
+                 sizeof(remote_act));
     break;
 
   case SIMCALL_COMM_TESTANY:
-    remote_act = mc_model_checker->process().read(remote(
-      simcall_comm_testany__get__comms(req) + idx));
+    remote_act = mc_model_checker->process().read(remote(simcall_comm_testany__getraw__comms(req) + idx));
     break;
 
   default:
     return true;
   }
 
-  simgrid::mc::Remote<simgrid::kernel::activity::Comm> temp_comm;
-  mc_model_checker->process().read(temp_comm, remote(
-    static_cast<simgrid::kernel::activity::Comm*>(remote_act)));
-  simgrid::kernel::activity::Comm* comm = temp_comm.getBuffer();
+  simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
+  mc_model_checker->process().read(temp_comm, remote(static_cast<simgrid::kernel::activity::CommImpl*>(remote_act)));
+  simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer();
   return comm->src_proc && comm->dst_proc;
 }
 
-bool actor_is_enabled(smx_actor_t actor)
-{
-  return simgrid::mc::request_is_enabled(&actor->simcall);
-}
 
 static const char* colors[] = {
   "blue",
@@ -491,18 +469,18 @@ std::string request_get_dot_output(smx_simcall_t req, int value)
       label = simgrid::xbt::string_printf("[(%lu)] iRecv", issuer->pid);
     break;
 
-  case SIMCALL_COMM_WAIT: {
+  case SIMCALL_COMM_WAIT:
     if (value == -1) {
       if (issuer->host)
         label = simgrid::xbt::string_printf("[(%lu)%s] WaitTimeout", issuer->pid, MC_smx_actor_get_host_name(issuer));
       else
         label = simgrid::xbt::string_printf("[(%lu)] WaitTimeout", issuer->pid);
     } else {
-      smx_activity_t remote_act = simcall_comm_wait__get__comm(req);
-      simgrid::mc::Remote<simgrid::kernel::activity::Comm> temp_comm;
-      mc_model_checker->process().read(temp_comm, remote(
-        static_cast<simgrid::kernel::activity::Comm*>(remote_act)));
-      simgrid::kernel::activity::Comm* comm = temp_comm.getBuffer();
+      simgrid::kernel::activity::ActivityImpl* remote_act = simcall_comm_wait__getraw__comm(req);
+      simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
+      mc_model_checker->process().read(temp_comm,
+                                       remote(static_cast<simgrid::kernel::activity::CommImpl*>(remote_act)));
+      simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer();
 
       smx_actor_t src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->src_proc));
       smx_actor_t dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_proc));
@@ -517,14 +495,12 @@ std::string request_get_dot_output(smx_simcall_t req, int value)
                     dst_proc ? dst_proc->pid : 0);
     }
     break;
-  }
 
   case SIMCALL_COMM_TEST: {
-    smx_activity_t remote_act = simcall_comm_test__get__comm(req);
-    simgrid::mc::Remote<simgrid::kernel::activity::Comm> temp_comm;
-    mc_model_checker->process().read(temp_comm, remote(
-      static_cast<simgrid::kernel::activity::Comm*>(remote_act)));
-    simgrid::kernel::activity::Comm* comm = temp_comm.getBuffer();
+    simgrid::kernel::activity::ActivityImpl* remote_act = simcall_comm_test__getraw__comm(req);
+    simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
+    mc_model_checker->process().read(temp_comm, remote(static_cast<simgrid::kernel::activity::CommImpl*>(remote_act)));
+    simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer();
     if (comm->src_proc == nullptr || comm->dst_proc == nullptr) {
       if (issuer->host)
         label = simgrid::xbt::string_printf("[(%lu)%s] Test FALSE", issuer->pid, MC_smx_actor_get_host_name(issuer));