X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1d83468696010801d74f8bc1e8c30918ffebabac..3907e83884bae6278656e9cd2cb7ef92a8f707fb:/src/mc/remote/RemotePtr.hpp diff --git a/src/mc/remote/RemotePtr.hpp b/src/mc/remote/RemotePtr.hpp index 6288fd5d02..16efc9354b 100644 --- a/src/mc/remote/RemotePtr.hpp +++ b/src/mc/remote/RemotePtr.hpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2008-2018. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2008-2023. 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. */ @@ -7,15 +6,9 @@ #ifndef SIMGRID_MC_REMOTE_PTR_HPP #define SIMGRID_MC_REMOTE_PTR_HPP -#include -#include -#include +#include "src/kernel/actor/ActorImpl.hpp" -#include -#include - -namespace simgrid { -namespace mc { +namespace simgrid::mc { /** HACK, A value from another process * @@ -25,41 +18,29 @@ namespace mc { * * * raw memory copy (std::memcpy) is used to copy Remote; * - * * raw memory comparison is used to compare them; - * * * when T is a trivial type, Remote is convertible to a T. * * We currently only handle the case where the type has the same layout * in the current process and in the target process: we don't handle * cross-architecture (such as 32-bit/64-bit access). */ -template union Remote { +template class Remote { private: - T buffer; + typename std::aligned_storage_t buffer; public: - Remote() { /* Nothing to do */} - ~Remote() { /* Nothing to do */} - Remote(T const& p) { std::memcpy(static_cast(&buffer), static_cast(&p), sizeof(buffer)); } - Remote(Remote const& that) - { - std::memcpy(static_cast(&buffer), static_cast(&that.buffer), sizeof(buffer)); - } - Remote& operator=(Remote const& that) - { - std::memcpy(static_cast(&buffer), static_cast(&that.buffer), sizeof(buffer)); - return *this; - } - T* getBuffer() { return &buffer; } - const T* getBuffer() const { return &buffer; } - std::size_t getBufferSize() const { return sizeof(T); } + Remote() = default; + explicit Remote(T const& p) { std::memcpy(&buffer, &p, sizeof buffer); } + + T* get_buffer() { return reinterpret_cast(&buffer); } + const T* get_buffer() const { return reinterpret_cast(&buffer); } + std::size_t get_buffer_size() const { return sizeof(T); } operator T() const { -//FIXME: assert turned off because smpi:Request is not seen as "trivial". -// static_assert(std::is_trivial::value, "Cannot convert non trivial type"); - return buffer; + static_assert(std::is_trivial_v, "Cannot convert non trivial type"); + return *get_buffer(); } - void clear() { std::memset(static_cast(&buffer), 0, sizeof(T)); } + void clear() { std::memset(&buffer, 0, sizeof buffer); } }; /** Pointer to a remote address-space (process, snapshot) @@ -77,14 +58,14 @@ public: * as a `uint64_t`. */ template class RemotePtr { - std::uint64_t address_; + std::uint64_t address_ = 0; public: - RemotePtr() : address_(0) {} - explicit RemotePtr(std::nullptr_t) : address_(0) {} + RemotePtr() = default; + explicit RemotePtr(std::nullptr_t) {} explicit RemotePtr(std::uint64_t address) : address_(address) {} explicit RemotePtr(T* address) : address_((std::uintptr_t)address) {} - explicit RemotePtr(Remote p) : address_((std::uintptr_t)*p.getBuffer()) {} + explicit RemotePtr(Remote p) : address_((std::uintptr_t)*p.get_buffer()) {} std::uint64_t address() const { return address_; } /** Turn into a local pointer @@ -153,7 +134,6 @@ template inline RemotePtr remote(uint64_t p) { return RemotePtr(p); } -} -} +} // namespace simgrid::mc #endif