Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
codacy
[simgrid.git] / src / mc / RegionSnapshot.hpp
index f1007ac..52deff2 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2007-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2007-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 <memory>
 #include <vector>
 
-#include <xbt/base.h>
+#include "xbt/base.h"
 
-#include "src/mc/remote_ptr.hpp"
-#include "src/mc/PageStore.hpp"
 #include "src/mc/AddressSpace.hpp"
 #include "src/mc/ChunkedData.hpp"
+#include "src/mc/PageStore.hpp"
+#include "src/mc/remote/RemotePtr.hpp"
 
 namespace simgrid {
 namespace mc {
@@ -29,7 +28,6 @@ enum class RegionType {
   Data = 2
 };
 
-// TODO, use Boost.Variant instead of this
 enum class StorageType {
   NoData = 0,
   Flat = 1,
@@ -37,37 +35,46 @@ enum class StorageType {
   Privatized = 3
 };
 
-class buffer {
-public:
+class Buffer {
+private:
   enum class Type {
     Malloc,
     Mmap
   };
-private:
   void* data_ = nullptr;
   std::size_t size_;
   Type type_ = Type::Malloc;
-public:
-  buffer() {}
-  buffer(std::size_t size, Type type = Type::Malloc);
-  buffer(void* data, std::size_t size, Type type = Type::Malloc) :
+private:
+  Buffer(std::size_t size, Type type = Type::Malloc);
+  Buffer(void* data, std::size_t size, Type type = Type::Malloc) :
     data_(data), size_(size), type_(type) {}
+public:
+  Buffer() = default;
   void clear() noexcept;
-  ~buffer() noexcept { clear(); }
+  ~Buffer() noexcept { clear(); }
+
+  static Buffer malloc(std::size_t size)
+  {
+    return Buffer(size, Type::Malloc);
+  }
+  static Buffer mmap(std::size_t size)
+  {
+    return Buffer(size, Type::Mmap);
+  }
 
   // No copy
-  buffer(buffer const& buffer) = delete;
-  buffer& operator=(buffer const& buffer) = delete;
+  Buffer(Buffer const& buffer) = delete;
+  Buffer& operator=(Buffer const& buffer) = delete;
 
   // Move
-  buffer(buffer&& that) noexcept
+  Buffer(Buffer&& that) noexcept
     : data_(that.data_), size_(that.size_), type_(that.type_)
   {
     that.data_ = nullptr;
     that.size_ = 0;
     that.type_ = Type::Malloc;
   }
-  buffer& operator=(buffer&& that) noexcept
+  Buffer& operator=(Buffer&& that) noexcept
   {
     clear();
     data_ = that.data_;
@@ -82,7 +89,6 @@ public:
   void* get()              { return data_; }
   const void* get()  const { return data_; }
   std::size_t size() const { return size_; }
-  Type type()        const { return type_; }
 };
 
 /** A copy/snapshot of a given memory region
@@ -94,9 +100,9 @@ public:
  *  * sparse/per-page snapshots are snaapshots which shared
  *    identical pages.
  *
- *  * privatized (SMPI global variable privatisation).
+ *  * privatized (SMPI global variable privatization).
  *
- *  This is handled with a variant based approch:
+ *  This is handled with a variant based approach:
  *
  *  * `storage_type` identified the type of storage;
  *
@@ -130,7 +136,7 @@ private:
    * */
   void *permanent_addr_;
 
-  buffer flat_data_;
+  Buffer flat_data_;
   ChunkedData page_numbers_;
   std::vector<RegionSnapshot> privatized_regions_;
 public:
@@ -150,20 +156,20 @@ public:
     size_(size),
     permanent_addr_(permanent_addr)
   {}
-  ~RegionSnapshot() {}
+  ~RegionSnapshot()                     = default;
   RegionSnapshot(RegionSnapshot const&) = default;
   RegionSnapshot& operator=(RegionSnapshot const&) = default;
   RegionSnapshot(RegionSnapshot&& that)
+      : region_type_(that.region_type_)
+      , storage_type_(that.storage_type_)
+      , object_info_(that.object_info_)
+      , start_addr_(that.start_addr_)
+      , size_(that.size_)
+      , permanent_addr_(that.permanent_addr_)
+      , flat_data_(std::move(that.flat_data_))
+      , page_numbers_(std::move(that.page_numbers_))
+      , privatized_regions_(std::move(that.privatized_regions_))
   {
-    region_type_ = that.region_type_;
-    storage_type_ = that.storage_type_;
-    object_info_ = that.object_info_;
-    start_addr_ = that.start_addr_;
-    size_ = that.size_;
-    permanent_addr_ = that.permanent_addr_;
-    flat_data_ = std::move(that.flat_data_);
-    page_numbers_ = std::move(that.page_numbers_);
-    privatized_regions_ = std::move(that.privatized_regions_);
     that.clear();
   }
   RegionSnapshot& operator=(RegionSnapshot&& that)
@@ -203,16 +209,16 @@ public:
     page_numbers_.clear();
     privatized_regions_.clear();
   }
-  
-  void flat_data(buffer data)
+
+  void flat_data(Buffer data)
   {
     storage_type_ = StorageType::Flat;
     flat_data_ = std::move(data);
     page_numbers_.clear();
     privatized_regions_.clear();
   }
-  const buffer& flat_data() const { return flat_data_; }
-  buffer& flat_data()             { return flat_data_; }
+  const Buffer& flat_data() const { return flat_data_; }
+  Buffer& flat_data()             { return flat_data_; }
 
   void page_data(ChunkedData page_data)
   {
@@ -244,14 +250,14 @@ public:
 
   // Other getters
 
-  remote_ptr<void> start() const { return remote(start_addr_); }
-  remote_ptr<void> end() const { return remote((char*)start_addr_ + size_); }
-  remote_ptr<void> permanent_address() const { return remote(permanent_addr_); }
+  RemotePtr<void> start() const { return remote(start_addr_); }
+  RemotePtr<void> end() const { return remote((char*)start_addr_ + size_); }
+  RemotePtr<void> permanent_address() const { return remote(permanent_addr_); }
   std::size_t size() const { return size_; }
   StorageType storage_type() const { return storage_type_; }
   RegionType region_type() const { return region_type_; }
 
-  bool contain(remote_ptr<void> p) const
+  bool contain(RemotePtr<void> p) const
   {
     return p >= start() && p < end();
   }
@@ -259,19 +265,17 @@ public:
 
 RegionSnapshot privatized_region(
     RegionType region_type, void *start_addr, void* permanent_addr,
-    std::size_t size, const RegionSnapshot* ref_region);
+    std::size_t size);
 RegionSnapshot dense_region(
   RegionType type, void *start_addr, void* data_addr, std::size_t size);
 simgrid::mc::RegionSnapshot sparse_region(
-  RegionType type, void *start_addr, void* data_addr, std::size_t size,
-  RegionSnapshot const* ref_region);
+  RegionType type, void *start_addr, void* data_addr, std::size_t size);
 simgrid::mc::RegionSnapshot region(
-  RegionType type, void *start_addr, void* data_addr, std::size_t size,
-  RegionSnapshot const* ref_region);
+  RegionType type, void *start_addr, void* data_addr, std::size_t size);
 
 }
 }
 
-typedef class simgrid::mc::RegionSnapshot s_mc_mem_region_t, *mc_mem_region_t;
-
+typedef class simgrid::mc::RegionSnapshot s_mc_mem_region_t;
+typedef s_mc_mem_region_t* mc_mem_region_t;
 #endif