Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a deleted flag to keep track of invalid but not actually deleted handles
[simgrid.git] / src / smpi / include / smpi_datatype.hpp
index bf01abb..3874680 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2009-2021. 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. */
@@ -30,7 +30,7 @@ constexpr unsigned DT_FLAG_DERIVED     = 0x0800; /**< is the datatype derived ?
 constexpr unsigned DT_FLAG_BASIC =
     (DT_FLAG_PREDEFINED | DT_FLAG_CONTIGUOUS | DT_FLAG_NO_GAPS | DT_FLAG_DATA | DT_FLAG_COMMITED);
 
-extern const MPI_Datatype MPI_PTR;
+extern MPI_Datatype MPI_PTR;
 
 //The following are datatypes for the MPI functions MPI_MAXLOC and MPI_MINLOC.
 struct float_int {
@@ -89,7 +89,7 @@ class Datatype_contents {
 };
 
 class Datatype : public F2C, public Keyval{
-  char* name_ = nullptr;
+  std::string name_ = "";
   /* The id here is the (unique) datatype id used for this datastructure.
    * It's default value is set to -1 since some code expects this return value
    * when no other id has been assigned
@@ -100,22 +100,27 @@ class Datatype : public F2C, public Keyval{
   MPI_Aint ub_;
   int flags_;
   int refcount_ = 1;
+  std::unique_ptr<Datatype_contents> contents_ = nullptr;
+
+protected:
+  template <typename... Args> void set_contents(Args&&... args)
+  {
+    contents_ = std::make_unique<Datatype_contents>(std::forward<Args>(args)...);
+  }
 
 public:
   static std::unordered_map<int, smpi_key_elem> keyvals_;
   static int keyval_id_;
-  Datatype_contents* contents_ = nullptr;
 
-  Datatype(int id, int size, MPI_Aint lb, MPI_Aint ub, int flags);
-  Datatype(char* name, int id, int size, MPI_Aint lb, MPI_Aint ub, int flags);
+  Datatype(int ident, int size, MPI_Aint lb, MPI_Aint ub, int flags);
+  Datatype(const char* name, int ident, int size, MPI_Aint lb, MPI_Aint ub, int flags);
   Datatype(int size, MPI_Aint lb, MPI_Aint ub, int flags);
-  Datatype(char* name, int size, MPI_Aint lb, MPI_Aint ub, int flags);
   Datatype(Datatype* datatype, int* ret);
   Datatype(const Datatype&) = delete;
   Datatype& operator=(const Datatype&) = delete;
-  virtual ~Datatype();
+  ~Datatype() override;
 
-  char* name() const { return name_; }
+  const char* name() const { return name_.c_str(); }
   size_t size() const { return size_; }
   MPI_Aint lb() const { return lb_; }
   MPI_Aint ub() const { return ub_; }