Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Typed template for Extendable::get_data.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 24 Jan 2022 15:58:05 +0000 (16:58 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 24 Jan 2022 16:48:02 +0000 (17:48 +0100)
15 files changed:
ChangeLog
examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp
examples/cpp/io-disk-raw/s4u-io-disk-raw.cpp
examples/cpp/io-file-system/s4u-io-file-system.cpp
include/xbt/Extendable.hpp
src/kernel/actor/ActorImpl.hpp
src/msg/msg_task.cpp
src/plugins/file_system/s4u_FileSystem.cpp
src/s4u/s4u_Actor.cpp
src/s4u/s4u_Disk.cpp
src/s4u/s4u_Host.cpp
src/s4u/s4u_Link.cpp
src/smpi/internals/smpi_global.cpp
teshsuite/s4u/basic-link-test/basic-link-test.cpp
teshsuite/s4u/storage_client_server/storage_client_server.cpp

index ec1a797..1419d43 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -36,6 +36,11 @@ SMPI:
    change injected costs for MPI_Recv, MPI_Send and MPI_Isend operations.
    Alternative for smpi/or, smpi/os and smpi/ois configuration options.
 
+XBT:
+ - Function xbt::Extendable::get_data() is now templated with the type of the
+   pointee. Untyped function is deprecated. Use get_data<void>() if you still
+   want to retrieve void*.
+
 Documentation:
  - New section: "SimGrid MPI calibration of a Grid5000 cluster"
    presenting how to properly calibrate MPI communications in SimGrid.
index 4f8334a..f2d1549 100644 (file)
@@ -20,24 +20,22 @@ struct HostAttribute {
 
 static double sg_host_get_available_at(const simgrid::s4u::Host* host)
 {
-  return static_cast<HostAttribute*>(host->get_data())->available_at;
+  return host->get_data<HostAttribute>()->available_at;
 }
 
 static void sg_host_set_available_at(const simgrid::s4u::Host* host, double time)
 {
-  auto* attr         = static_cast<HostAttribute*>(host->get_data());
-  attr->available_at = time;
+  host->get_data<HostAttribute>()->available_at = time;
 }
 
 static simgrid::s4u::Exec* sg_host_get_last_scheduled_task(const simgrid::s4u::Host* host)
 {
-  return static_cast<HostAttribute*>(host->get_data())->last_scheduled_task;
+  return host->get_data<HostAttribute>()->last_scheduled_task;
 }
 
 static void sg_host_set_last_scheduled_task(const simgrid::s4u::Host* host, simgrid::s4u::ExecPtr task)
 {
-  auto* attr                = static_cast<HostAttribute*>(host->get_data());
-  attr->last_scheduled_task = task.get();
+  host->get_data<HostAttribute>()->last_scheduled_task = task.get();
 }
 
 static bool dependency_exists(const simgrid::s4u::Exec* src, simgrid::s4u::Exec* dst)
@@ -102,7 +100,7 @@ static double finish_on_at(const simgrid::s4u::ExecPtr task, const simgrid::s4u:
         }
         // We use the user data field to store the finish time of the predecessor of the comm, i.e., its potential start
         // time
-        data_available = *(static_cast<double*>(comm->get_data())) + redist_time;
+        data_available = *comm->get_data<double>() + redist_time;
       }
 
       const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(parent.get());
@@ -148,7 +146,7 @@ static void schedule_on(simgrid::s4u::ExecPtr exec, simgrid::s4u::Host* host)
     auto* comm = dynamic_cast<simgrid::s4u::Comm*>(pred.get());
     if (comm != nullptr) {
       comm->set_destination(host);
-      delete static_cast<double*>(comm->get_data());
+      delete comm->get_data<double>();
     }
   }
   // we can also set the source of all the output comms of this exec
index 925291f..d86b014 100644 (file)
@@ -42,12 +42,12 @@ static void host()
   /* - Attach some user data to disk1 */
   XBT_INFO("*** Get/set data for storage element: Disk1 ***");
 
-  const auto* data = static_cast<std::string*>(disk->get_data());
+  const auto* data = disk->get_data<std::string>();
 
   XBT_INFO("Get storage data: '%s'", data ? data->c_str() : "No user data");
 
   disk->set_data(new std::string("Some user data"));
-  data = static_cast<std::string*>(disk->get_data());
+  data = disk->get_data<std::string>();
   XBT_INFO("Set and get data: '%s'", data->c_str());
   delete data;
 }
index bc745d1..3dc82a0 100644 (file)
@@ -57,7 +57,7 @@ public:
 
     // Test attaching some user data to the file
     file->set_data(new std::string("777"));
-    const auto* file_data = static_cast<std::string*>(file->get_data());
+    const auto* file_data = file->get_data<std::string>();
     XBT_INFO("User data attached to the file: %s", file_data->c_str());
     delete file_data;
 
index ccfa937..195f287 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef SIMGRID_XBT_LIB_HPP
 #define SIMGRID_XBT_LIB_HPP
 
+#include "xbt/base.h" // XBT_ATTRIB_DEPRECATED_v334
 #include <cstddef>
 #include <limits>
 #include <vector>
@@ -111,7 +112,11 @@ public:
   void set_data(void* data){
     extensions_[0]=data;
   }
-  void* get_data() const { return extensions_[0]; }
+  template <typename D> D* get_data() const { return static_cast<D*>(extensions_[0]); }
+  XBT_ATTRIB_DEPRECATED_v334("Please use typed template Extendable::get_data<>()") void* get_data() const
+  {
+    return get_data<void>();
+  }
   // Convenience extension access when the type has an associated EXTENSION ID:
   template <class U> U* extension() const { return extension<U>(U::EXTENSION_ID); }
   template<class U> void extension_set(U* p) { extension_set<U>(U::EXTENSION_ID, p); }
index 678de9a..ce54dfc 100644 (file)
@@ -181,7 +181,7 @@ public:
   explicit ProcessArg(s4u::Host* host, ActorImpl* actor)
       : name(actor->get_name())
       , code(actor->code_)
-      , data(actor->get_ciface()->get_data())
+      , data(actor->get_ciface()->get_data<void>())
       , host(host)
       , kill_time(actor->get_kill_time())
       , auto_restart(actor->has_to_auto_restart())
index 968a798..d17bed8 100644 (file)
@@ -246,7 +246,7 @@ msg_task_t MSG_parallel_task_create(const char *name, int host_nb, const msg_hos
 /** @brief Return the user data of the given task */
 void* MSG_task_get_data(const_msg_task_t task)
 {
-  return task->get_data();
+  return task->get_data<void>();
 }
 
 /** @brief Sets the user data of a given task */
index 07a10c1..51d3ccc 100644 (file)
@@ -521,7 +521,7 @@ void sg_file_dump(const_sg_file_t fd)
  */
 void* sg_file_get_data(const_sg_file_t fd)
 {
-  return fd->get_data();
+  return fd->get_data<void>();
 }
 
 /** Changes the user data associated with the file
index 2136988..d4bd80d 100644 (file)
@@ -756,7 +756,7 @@ const char* sg_actor_self_get_name()
 
 void* sg_actor_self_get_data()
 {
-  return simgrid::s4u::Actor::self()->get_data();
+  return simgrid::s4u::Actor::self()->get_data<void>();
 }
 
 void sg_actor_self_set_data(void* userdata)
@@ -805,7 +805,7 @@ void sg_actor_unref(const_sg_actor_t actor)
 /** @brief Return the user data of a #sg_actor_t */
 void* sg_actor_get_data(const_sg_actor_t actor)
 {
-  return actor->get_data();
+  return actor->get_data<void>();
 }
 
 /** @brief Set the user data of a #sg_actor_t */
index 91b3faa..b95164d 100644 (file)
@@ -213,7 +213,7 @@ sg_size_t sg_disk_write(const_sg_disk_t disk, sg_size_t size)
 
 void* sg_disk_get_data(const_sg_disk_t disk)
 {
-  return disk->get_data();
+  return disk->get_data<void>();
 }
 
 void sg_disk_set_data(sg_disk_t disk, void* data)
index aa56f77..63d0302 100644 (file)
@@ -462,7 +462,7 @@ sg_host_t sg_host_by_name(const char* name)
 // ========== User data Layer ==========
 void* sg_host_get_data(const_sg_host_t host)
 {
-  return host->get_data();
+  return host->get_data<void>();
 }
 void sg_host_set_data(sg_host_t host, void* userdata)
 {
index af8ae86..ff36c71 100644 (file)
@@ -254,7 +254,7 @@ void sg_link_set_latency(sg_link_t link, double value)
 
 void* sg_link_get_data(const_sg_link_t link)
 {
-  return link->get_data();
+  return link->get_data<void>();
 }
 
 void sg_link_set_data(sg_link_t link, void* data)
index 34a53e5..b8297e4 100644 (file)
@@ -120,7 +120,7 @@ MPI_Info smpi_process_info_env(){
 }
 
 void * smpi_process_get_user_data(){
-  return simgrid::s4u::Actor::self()->get_data();
+  return simgrid::s4u::Actor::self()->get_data<void>();
 }
 
 void smpi_process_set_user_data(void *data){
index 14380a5..bf6013a 100644 (file)
@@ -29,7 +29,7 @@ int main(int argc, char** argv)
   for (const auto& l : links) {
     XBT_INFO("%s: latency = %.5f, bandwidth = %f", l->get_cname(), l->get_latency(), l->get_bandwidth());
     l->set_data(&user_data);
-    xbt_assert(user_data == *static_cast<const std::string*>(l->get_data()), "User data was corrupted.");
+    xbt_assert(user_data == *l->get_data<std::string>(), "User data was corrupted.");
   }
 
   return 0;
index 232c092..8682197 100644 (file)
@@ -74,10 +74,10 @@ static void get_set_disk_data(simgrid::s4u::Disk* disk)
 {
   XBT_INFO("*** GET/SET DATA for disk: %s ***", disk->get_cname());
 
-  const std::string* data = static_cast<std::string*>(disk->get_data());
+  const std::string* data = disk->get_data<std::string>();
   XBT_INFO("Get data: '%s'", data ? data->c_str() : "No User Data");
   disk->set_data(new std::string("Some data"));
-  data = static_cast<std::string*>(disk->get_data());
+  data = disk->get_data<std::string>();
   XBT_INFO("  Set and get data: '%s'", data->c_str());
   delete data;
 }