Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Replace ReadMode with strongly-type/safe ReadOptions
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 22 Feb 2016 11:22:40 +0000 (12:22 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 22 Feb 2016 11:22:40 +0000 (12:22 +0100)
src/mc/AddressSpace.hpp
src/mc/Process.cpp
src/mc/Process.hpp
src/mc/mc_compare.cpp
src/mc/mc_snapshot.cpp
src/mc/mc_snapshot.h

index 41f1f8b..159642f 100644 (file)
@@ -132,6 +132,63 @@ const int ProcessIndexDisabled = -2;
  */
 const int ProcessIndexAny = 0;
 
  */
 const int ProcessIndexAny = 0;
 
+/** Options for read operations
+ *
+ *  This is a set of flags managed with bitwise operators. Only the
+ *  meaningful operations are defined: addition, conversions to/from
+ *  integers are not allowed.
+ */
+class ReadOptions {
+  std::uint32_t value_;
+  constexpr explicit ReadOptions(std::uint32_t value) : value_(value) {}
+public:
+  constexpr ReadOptions() : value_(0) {}
+
+  constexpr operator bool() const { return value_ != 0; }
+  constexpr operator!() const { return value_ == 0; }
+
+  constexpr ReadOptions operator|(ReadOptions const& that) const
+  {
+    return ReadOptions(value_ | that.value_);
+  }
+  constexpr ReadOptions operator&(ReadOptions const& that) const
+  {
+    return ReadOptions(value_ & that.value_);
+  }
+  constexpr ReadOptions operator^(ReadOptions const& that) const
+  {
+    return ReadOptions(value_ ^ that.value_);
+  }
+  constexpr ReadOptions operator~() const
+  {
+    return ReadOptions(~value_);
+  }
+
+  ReadOptions& operator|=(ReadOptions const& that)
+  {
+    value_ |= that.value_;
+    return *this;
+  }
+  ReadOptions& operator&=(ReadOptions const& that)
+  {
+    value_ &= that.value_;
+    return *this;
+  }
+  ReadOptions& operator^=(ReadOptions const& that)
+  {
+    value_ &= that.value_;
+    return *this;
+  }
+
+  /** Copy the data to the given buffer */
+  static constexpr ReadOptions none() { return ReadOptions(0); }
+
+  /** Allows to return a pointer to another buffer where the data is
+   *  available instead of copying the data into the buffer
+   */
+  static constexpr ReadOptions lazy() { return ReadOptions(1); }
+};
+
 /** A given state of a given process (abstract base class)
  *
  *  Currently, this might either be:
 /** A given state of a given process (abstract base class)
  *
  *  Currently, this might either be:
@@ -144,21 +201,6 @@ class AddressSpace {
 private:
   Process* process_;
 public:
 private:
   Process* process_;
 public:
-  enum ReadMode {
-
-    /** Copy the data to the given buffer */
-    Normal,
-
-    /** Allows the `read_bytes` to return a pointer to another buffer
-     *  where the data is available instead of copying the data into the
-     *  buffer.
-     *
-     *  This adds quite a level of ugliness but it was found to more
-     *  efficient at some point. We should check if there is still
-     *  a noticeable different and get rid of it.
-     */
-    Lazy
-  };
   AddressSpace(Process* process) : process_(process) {}
   virtual ~AddressSpace();
 
   AddressSpace(Process* process) : process_(process) {}
   virtual ~AddressSpace();
 
@@ -170,11 +212,11 @@ public:
    *  @param size          number of bytes
    *  @param address       remote source address of the data
    *  @param process_index which process (used for SMPI privatization)
    *  @param size          number of bytes
    *  @param address       remote source address of the data
    *  @param process_index which process (used for SMPI privatization)
-   *  @param mode
+   *  @param options
    */
   virtual const void* read_bytes(void* buffer, std::size_t size,
     remote_ptr<void> address, int process_index = ProcessIndexAny,
    */
   virtual const void* read_bytes(void* buffer, std::size_t size,
     remote_ptr<void> address, int process_index = ProcessIndexAny,
-    ReadMode mode = Normal) const = 0;
+    ReadOptions options = ReadOptions::none()) const = 0;
 
   /** Read a given data structure from the address space */
   template<class T> inline
 
   /** Read a given data structure from the address space */
   template<class T> inline
index d7e12bf..2e6d792 100644 (file)
@@ -506,7 +506,7 @@ char* Process::read_string(remote_ptr<void> address) const
 
 const void *Process::read_bytes(void* buffer, std::size_t size,
   remote_ptr<void> address, int process_index,
 
 const void *Process::read_bytes(void* buffer, std::size_t size,
   remote_ptr<void> address, int process_index,
-  AddressSpace::ReadMode mode) const
+  ReadOptions options) const
 {
   if (process_index != simgrid::mc::ProcessIndexDisabled) {
     std::shared_ptr<simgrid::mc::ObjectInformation> const& info =
 {
   if (process_index != simgrid::mc::ProcessIndexDisabled) {
     std::shared_ptr<simgrid::mc::ObjectInformation> const& info =
index 2f51240..8780e3c 100644 (file)
@@ -75,7 +75,7 @@ public:
   // Read memory:
   const void* read_bytes(void* buffer, std::size_t size,
     remote_ptr<void> address, int process_index = ProcessIndexAny,
   // Read memory:
   const void* read_bytes(void* buffer, std::size_t size,
     remote_ptr<void> address, int process_index = ProcessIndexAny,
-    ReadMode mode = Normal) const override;
+    ReadOptions options = ReadOptions::none()) const override;
   void read_variable(const char* name, void* target, size_t size) const;
   template<class T>
   T read_variable(const char *name) const
   void read_variable(const char* name, void* target, size_t size) const;
   template<class T>
   T read_variable(const char *name) const
index daf84c8..dd6dd27 100644 (file)
@@ -440,11 +440,11 @@ int snapshot_compare(void *state1, void *state2)
   xbt_mheap_t heap1 = (xbt_mheap_t)s1->read_bytes(
     alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
     remote(process->heap_address),
   xbt_mheap_t heap1 = (xbt_mheap_t)s1->read_bytes(
     alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
     remote(process->heap_address),
-    simgrid::mc::ProcessIndexMissing, simgrid::mc::AddressSpace::Lazy);
+    simgrid::mc::ProcessIndexMissing, simgrid::mc::ReadOptions::lazy());
   xbt_mheap_t heap2 = (xbt_mheap_t)s2->read_bytes(
     alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
     remote(process->heap_address),
   xbt_mheap_t heap2 = (xbt_mheap_t)s2->read_bytes(
     alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
     remote(process->heap_address),
-    simgrid::mc::ProcessIndexMissing, simgrid::mc::AddressSpace::Lazy);
+    simgrid::mc::ProcessIndexMissing, simgrid::mc::ReadOptions::lazy());
   res_init = init_heap_information(heap1, heap2, &s1->to_ignore, &s2->to_ignore);
   if (res_init == -1) {
 #ifdef MC_DEBUG
   res_init = init_heap_information(heap1, heap2, &s1->to_ignore, &s2->to_ignore);
   if (res_init == -1) {
 #ifdef MC_DEBUG
@@ -520,7 +520,8 @@ int snapshot_compare(void *state1, void *state2)
 
     /* Compare global variables */
     is_diff =
 
     /* Compare global variables */
     is_diff =
-      compare_global_variables(region1->object_info(  ), simgrid::mc::AddressSpace::Normal,
+      compare_global_variables(region1->object_info(),
+        simgrid::mc::ProcessIndexDisabled,
         region1, region2,
         s1, s2);
 
         region1, region2,
         s1, s2);
 
index a1ea070..ec1bd47 100644 (file)
@@ -171,12 +171,12 @@ Snapshot::~Snapshot()
 
 const void* Snapshot::read_bytes(void* buffer, std::size_t size,
   remote_ptr<void> address, int process_index,
 
 const void* Snapshot::read_bytes(void* buffer, std::size_t size,
   remote_ptr<void> address, int process_index,
-  AddressSpace::ReadMode mode) const
+  ReadOptions options) const
 {
   mc_mem_region_t region = mc_get_snapshot_region((void*)address.address(), this, process_index);
   if (region) {
     const void* res = MC_region_read(region, buffer, (void*)address.address(), size);
 {
   mc_mem_region_t region = mc_get_snapshot_region((void*)address.address(), this, process_index);
   if (region) {
     const void* res = MC_region_read(region, buffer, (void*)address.address(), size);
-    if (buffer == res || mode == AddressSpace::Lazy)
+    if (buffer == res || options & ReadOptions::lazy())
       return res;
     else {
       memcpy(buffer, res, size);
       return res;
     else {
       memcpy(buffer, res, size);
@@ -185,7 +185,7 @@ const void* Snapshot::read_bytes(void* buffer, std::size_t size,
   }
   else
     return this->process()->read_bytes(
   }
   else
     return this->process()->read_bytes(
-      buffer, size, address, process_index, mode);
+      buffer, size, address, process_index, options);
 }
 
 }
 }
 
 }
index 5c638f6..8960b45 100644 (file)
@@ -146,7 +146,7 @@ public:
   ~Snapshot();
   const void* read_bytes(void* buffer, std::size_t size,
     remote_ptr<void> address, int process_index = ProcessIndexAny,
   ~Snapshot();
   const void* read_bytes(void* buffer, std::size_t size,
     remote_ptr<void> address, int process_index = ProcessIndexAny,
-    ReadMode mode = Normal) const override;
+    ReadOptions options = ReadOptions::none()) const override;
 public: // To be private
   int num_state;
   std::size_t heap_bytes_used;
 public: // To be private
   int num_state;
   std::size_t heap_bytes_used;