Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
don't use char* for pointers that shall be serialized with >>
[simgrid.git] / src / mc / Transition.hpp
index d8566a2..8bf38a9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015-2018. The SimGrid Team.
+/* Copyright (c) 2015-2022. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -7,6 +7,11 @@
 #ifndef SIMGRID_MC_TRANSITION_HPP
 #define SIMGRID_MC_TRANSITION_HPP
 
+#include "simgrid/forward.h" // aid_t
+#include "src/kernel/actor/SimcallObserver.hpp"
+#include "src/mc/remote/RemotePtr.hpp"
+#include <string>
+
 namespace simgrid {
 namespace mc {
 
@@ -19,8 +24,17 @@ namespace mc {
  *  calls.
  */
 class Transition {
+  /* Textual representation of the transition, to display backtraces */
+  static unsigned long executed_transitions_;
+  static unsigned long replayed_transitions_;
+
+  friend State; // FIXME remove this once we have a proper class to handle the statistics
+
+protected:
+  std::string textual_ = "";
+
 public:
-  int pid = 0;
+  aid_t aid_ = 0;
 
   /* Which transition was executed for this simcall
    *
@@ -30,10 +44,74 @@ public:
    *
    * * random can produce different values.
    */
-  int argument = 0;
+  int times_considered_ = 0;
+
+  Transition() = default;
+  Transition(aid_t issuer, int times_considered) : aid_(issuer), times_considered_(times_considered) {}
+
+  void init(aid_t aid, int times_considered);
+
+  virtual std::string to_string(bool verbose = false);
+  const char* to_cstring(bool verbose = false);
+
+  /* Moves the application toward a path that was already explored, but don't change the current transition */
+  void replay() const;
+
+  virtual bool depends(const Transition* other) const { return true; }
+
+  /* Returns the total amount of transitions executed so far (for statistics) */
+  static unsigned long get_executed_transitions() { return executed_transitions_; }
+  /* Returns the total amount of transitions replayed so far while backtracing (for statistics) */
+  static unsigned long get_replayed_transitions() { return replayed_transitions_; }
+};
+
+class CommSendTransition;
+class CommRecvTransition;
+
+class CommWaitTransition : public Transition {
+  double timeout_;
+  void* comm_;
+  aid_t sender_;
+  aid_t receiver_;
+  unsigned mbox_;
+  void* src_buff_;
+  void* dst_buff_;
+  size_t size_;
+  friend CommSendTransition;
+  friend CommRecvTransition;
+
+public:
+  CommWaitTransition(aid_t issuer, int times_considered, char* buffer);
+  std::string to_string(bool verbose) override;
+  bool depends(const Transition* other) const override;
+};
+
+class CommRecvTransition : public Transition {
+  unsigned mbox_;
+  void* dst_buff_;
+
+public:
+  CommRecvTransition(aid_t issuer, int times_considered, char* buffer);
+  std::string to_string(bool verbose) override;
+  bool depends(const Transition* other) const override;
+};
+
+class CommSendTransition : public Transition {
+  unsigned mbox_;
+  void* src_buff_;
+  size_t size_;
+
+public:
+  CommSendTransition(aid_t issuer, int times_considered, char* buffer);
+  std::string to_string(bool verbose) override;
+  bool depends(const Transition* other) const override;
 };
 
-}
-}
+/** Make a new transition from serialized description */
+Transition* recv_transition(aid_t issuer, int times_considered, kernel::actor::SimcallObserver::Simcall simcall,
+                            char* buffer);
+
+} // namespace mc
+} // namespace simgrid
 
 #endif