X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ba9a4cfeba4eb00e84cd17603fc9654e81445655..61427a88a76a2c2ef25d0d5b8132995c6f550e5c:/src/mc/RegionSnapshot.hpp diff --git a/src/mc/RegionSnapshot.hpp b/src/mc/RegionSnapshot.hpp index a0031910ec..8fd9e60490 100644 --- a/src/mc/RegionSnapshot.hpp +++ b/src/mc/RegionSnapshot.hpp @@ -13,12 +13,12 @@ #include #include -#include +#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 +29,6 @@ enum class RegionType { Data = 2 }; -// TODO, use Boost.Variant instead of this enum class StorageType { NoData = 0, Flat = 1, @@ -37,22 +36,61 @@ enum class StorageType { Privatized = 3 }; -class data_deleter { -public: - enum Type { - Free, - Munmap - }; +class Buffer { private: - Type type_; + enum class Type { + Malloc, + Mmap + }; + void* data_ = nullptr; 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: - data_deleter() : type_(Free) {} - data_deleter(Type type, std::size_t size) : type_(type), size_(size) {} - void operator()(void* p) const; -}; + Buffer() = default; + void clear() noexcept; + ~Buffer() noexcept { clear(); } -typedef std::unique_ptr unique_data_ptr; + 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; + + // Move + 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 + { + clear(); + data_ = that.data_; + size_ = that.size_; + type_ = that.type_; + that.data_ = nullptr; + that.size_ = 0; + that.type_ = Type::Malloc; + return *this; + } + + void* get() { return data_; } + const void* get() const { return data_; } + std::size_t size() const { return size_; } +}; /** A copy/snapshot of a given memory region * @@ -65,7 +103,7 @@ typedef std::unique_ptr unique_data_ptr; * * * privatized (SMPI global variable privatisation). * - * This is handled with a variant based approch: + * This is handled with a variant based approach: * * * `storage_type` identified the type of storage; * @@ -77,8 +115,6 @@ public: static const RegionType UnknownRegion = RegionType::Unknown; static const RegionType HeapRegion = RegionType::Heap; static const RegionType DataRegion = RegionType::Data; -public: - typedef unique_data_ptr flat_data_ptr; private: RegionType region_type_; StorageType storage_type_; @@ -101,7 +137,7 @@ private: * */ void *permanent_addr_; - flat_data_ptr flat_data_; + Buffer flat_data_; ChunkedData page_numbers_; std::vector privatized_regions_; public: @@ -121,7 +157,7 @@ public: size_(size), permanent_addr_(permanent_addr) {} - ~RegionSnapshot() {} + ~RegionSnapshot() = default; RegionSnapshot(RegionSnapshot const&) = default; RegionSnapshot& operator=(RegionSnapshot const&) = default; RegionSnapshot(RegionSnapshot&& that) @@ -160,7 +196,7 @@ public: storage_type_ = StorageType::NoData; privatized_regions_.clear(); page_numbers_.clear(); - flat_data_.reset(); + flat_data_.clear(); object_info_ = nullptr; start_addr_ = nullptr; size_ = 0; @@ -170,24 +206,25 @@ public: void clear_data() { storage_type_ = StorageType::NoData; - flat_data_.reset(); + flat_data_.clear(); page_numbers_.clear(); privatized_regions_.clear(); } - - void flat_data(flat_data_ptr data) + + void flat_data(Buffer data) { storage_type_ = StorageType::Flat; flat_data_ = std::move(data); page_numbers_.clear(); privatized_regions_.clear(); } - const char* flat_data() const { return flat_data_.get(); } + const Buffer& flat_data() const { return flat_data_; } + Buffer& flat_data() { return flat_data_; } void page_data(ChunkedData page_data) { storage_type_ = StorageType::Chunked; - flat_data_.reset(); + flat_data_.clear(); page_numbers_ = std::move(page_data); privatized_regions_.clear(); } @@ -196,7 +233,7 @@ public: void privatized_data(std::vector data) { storage_type_ = StorageType::Privatized; - flat_data_.reset(); + flat_data_.clear(); page_numbers_.clear(); privatized_regions_ = std::move(data); } @@ -214,14 +251,14 @@ public: // Other getters - remote_ptr start() const { return remote(start_addr_); } - remote_ptr end() const { return remote((char*)start_addr_ + size_); } - remote_ptr permanent_address() const { return remote(permanent_addr_); } + RemotePtr start() const { return remote(start_addr_); } + RemotePtr end() const { return remote((char*)start_addr_ + size_); } + RemotePtr 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 p) const + bool contain(RemotePtr p) const { return p >= start() && p < end(); } @@ -229,19 +266,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