Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use typed Mailbox::get<>() instead of using static_cast everywhere.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 17 Dec 2020 09:01:36 +0000 (10:01 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 17 Dec 2020 11:46:09 +0000 (12:46 +0100)
51 files changed:
docs/source/tuto_s4u/master-workers-lab1.cpp
docs/source/tuto_s4u/master-workers-lab2.cpp
docs/source/tuto_s4u/master-workers-lab3.cpp
docs/source/tuto_s4u/master-workers-lab4.cpp
examples/s4u/actor-create/s4u-actor-create.cpp
examples/s4u/actor-exiting/s4u-actor-exiting.cpp
examples/s4u/app-bittorrent/s4u-peer.cpp
examples/s4u/app-chainsend/s4u-app-chainsend.cpp
examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp
examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp
examples/s4u/app-pingpong/s4u-app-pingpong.cpp
examples/s4u/app-token-ring/s4u-app-token-ring.cpp
examples/s4u/cloud-simple/s4u-cloud-simple.cpp
examples/s4u/comm-ready/s4u-comm-ready.cpp
examples/s4u/comm-suspend/s4u-comm-suspend.cpp
examples/s4u/comm-waitall/s4u-comm-waitall.cpp
examples/s4u/comm-waitany/s4u-comm-waitany.cpp
examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp
examples/s4u/energy-link/s4u-energy-link.cpp
examples/s4u/energy-wifi/s4u-energy-wifi.cpp
examples/s4u/maestro-set/s4u-maestro-set.cpp
examples/s4u/mc-bugged1-liveness/s4u-mc-bugged1-liveness.cpp
examples/s4u/mc-bugged1/s4u-mc-bugged1.cpp
examples/s4u/mc-bugged2/s4u-mc-bugged2.cpp
examples/s4u/mc-failing-assert/s4u-mc-failing-assert.cpp
examples/s4u/network-ns3-wifi/s4u-network-ns3-wifi.cpp
examples/s4u/network-ns3/s4u-network-ns3.cpp
examples/s4u/network-wifi/s4u-network-wifi.cpp
examples/s4u/platform-failures/s4u-platform-failures.cpp
examples/s4u/plugin-link-load/s4u-plugin-link-load.cpp
examples/s4u/replay-comm/s4u-replay-comm.cpp
examples/s4u/trace-categories/s4u-trace-categories.cpp
examples/s4u/trace-masterworkers/s4u-trace-masterworkers.cpp
examples/s4u/trace-process-migration/s4u-trace-process-migration.cpp
examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp
src/bindings/python/simgrid_python.cpp
src/plugins/vm/VmLiveMigration.cpp
teshsuite/mc/mutex-handling/mutex-handling.cpp
teshsuite/s4u/activity-lifecycle/testing_comm.cpp
teshsuite/s4u/actor-suspend/actor-suspend.cpp
teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp
teshsuite/s4u/host-on-off-actors/host-on-off-actors.cpp
teshsuite/s4u/host-on-off-recv/host-on-off-recv.cpp
teshsuite/s4u/host-on-off/host-on-off.cpp
teshsuite/s4u/listen_async/listen_async.cpp
teshsuite/s4u/ns3-from-src-to-itself/ns3-from-src-to-itself.cpp
teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.cpp
teshsuite/s4u/pid/pid.cpp
teshsuite/s4u/storage_client_server/storage_client_server.cpp
teshsuite/surf/wifi_usage/wifi_usage.cpp
teshsuite/surf/wifi_usage_decay/wifi_usage_decay.cpp

index c71c60b..12fcdda 100644 (file)
@@ -58,7 +58,7 @@ static void worker(std::vector<std::string> args)
 
   double compute_cost;
   do {
-    double* msg  = static_cast<double*>(mailbox->get());
+    double* msg  = mailbox->get<double>();
     compute_cost = *msg;
     delete msg;
 
index 573c5f3..df78adf 100644 (file)
@@ -23,7 +23,7 @@ static void worker()
 
   double compute_cost;
   do {
-    double* msg  = static_cast<double*>(mailbox->get());
+    double* msg  = mailbox->get<double>();
     compute_cost = *msg;
     delete msg;
 
index 3061942..a2f3963 100644 (file)
@@ -22,7 +22,7 @@ static void worker()
   simgrid::s4u::Mailbox* mailbox   = simgrid::s4u::Mailbox::by_name(mailbox_name);
 
   while (true) { // Master forcefully kills the workers by the end of the simulation
-    double* msg  = static_cast<double*>(mailbox->get());
+    double* msg         = mailbox->get<double>();
     double compute_cost = *msg;
     delete msg;
 
index bfb4168..7752e31 100644 (file)
@@ -22,7 +22,7 @@ static void worker(std::string category)
   simgrid::s4u::Mailbox* mailbox   = simgrid::s4u::Mailbox::by_name(mailbox_name);
 
   while (true) { // Master forcefully kills the workers by the end of the simulation
-    double* msg         = static_cast<double*>(mailbox->get());
+    double* msg         = mailbox->get<double>();
     double compute_cost = *msg;
     delete msg;
 
index 874e36a..d8ce9e8 100644 (file)
@@ -33,9 +33,9 @@ static void receiver(const std::string& mailbox_name)
 
   XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->get_cname());
 
-  const auto* msg1 = static_cast<std::string*>(mailbox->get());
-  const auto* msg2 = static_cast<std::string*>(mailbox->get());
-  const auto* msg3 = static_cast<std::string*>(mailbox->get());
+  const auto* msg1 = mailbox->get<std::string>();
+  const auto* msg2 = mailbox->get<std::string>();
+  const auto* msg3 = mailbox->get<std::string>();
   XBT_INFO("I received '%s', '%s' and '%s'", msg1->c_str(), msg2->c_str(), msg3->c_str());
   delete msg1;
   delete msg2;
@@ -49,7 +49,7 @@ static void forwarder(int argc, char** argv)
   xbt_assert(argc >= 3, "Actor forwarder requires 2 parameters, but got only %d", argc - 1);
   simgrid::s4u::Mailbox* in    = simgrid::s4u::Mailbox::by_name(argv[1]);
   simgrid::s4u::Mailbox* out   = simgrid::s4u::Mailbox::by_name(argv[2]);
-  auto* msg                    = static_cast<std::string*>(in->get());
+  auto* msg                    = in->get<std::string>();
   XBT_INFO("Forward '%s'.", msg->c_str());
   out->put(msg, msg->size());
 }
index aa2215b..ecc2e95 100644 (file)
@@ -64,7 +64,7 @@ static void actor_c()
 
   simgrid::s4u::this_actor::sleep_for(3);
   XBT_INFO("And now, induce a deadlock by waiting for a message that will never come\n\n");
-  simgrid::s4u::Mailbox::by_name("nobody")->get();
+  simgrid::s4u::Mailbox::by_name("nobody")->get<void>();
   xbt_die("Receiving is not supposed to succeed when nobody is sending");
 }
 
index f147320..06cc7b5 100644 (file)
@@ -116,7 +116,7 @@ bool Peer::getPeersFromTracker()
   }
 
   try {
-    auto* answer = static_cast<TrackerAnswer*>(mailbox_->get(GET_PEERS_TIMEOUT));
+    auto* answer = mailbox_->get<TrackerAnswer>(GET_PEERS_TIMEOUT);
     // Add the peers the tracker gave us to our peer list.
     for (auto const& peer_id : answer->getPeers())
       if (id != peer_id)
index d04d43e..cf028a1 100644 (file)
@@ -47,7 +47,7 @@ public:
 
   void joinChain()
   {
-    const auto* msg   = static_cast<ChainMessage*>(me->get());
+    const auto* msg   = me->get<ChainMessage>();
     prev              = msg->prev_;
     next              = msg->next_;
     total_pieces      = msg->num_pieces;
index 7dd3860..e65a85c 100644 (file)
@@ -67,7 +67,7 @@ public:
   {
     double compute_cost;
     do {
-      const auto* msg = static_cast<double*>(mailbox->get());
+      const auto* msg = mailbox->get<double>();
       compute_cost = *msg;
       delete msg;
 
index 72ff9cd..f255aac 100644 (file)
@@ -54,7 +54,7 @@ static void worker(std::vector<std::string> args)
 
   double compute_cost;
   do {
-    const auto* msg = static_cast<double*>(mailbox->get());
+    const auto* msg = mailbox->get<double>();
     compute_cost = *msg;
     delete msg;
 
index 9407c7c..0404107 100644 (file)
@@ -16,7 +16,7 @@ static void pinger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mai
 
   mailbox_out->put(payload, 1);
   /* - ... then wait for the (large) pong */
-  const auto* sender_time = static_cast<double*>(mailbox_in->get());
+  const auto* sender_time = mailbox_in->get<double>();
 
   double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
   XBT_INFO("Payload received : large communication (bandwidth bound)");
@@ -29,7 +29,7 @@ static void ponger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mai
   XBT_INFO("Pong from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
 
   /* - Receive the (small) ping first ....*/
-  const auto* sender_time   = static_cast<double*>(mailbox_in->get());
+  const auto* sender_time   = mailbox_in->get<double>();
   double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
   XBT_INFO("Payload received : small communication (latency bound)");
   XBT_INFO("Ping time (latency bound) %f", communication_time);
index 801cebb..d96c97e 100644 (file)
@@ -40,10 +40,10 @@ public:
       XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->get_cname());
       std::string msg = "Token";
       neighbor_mailbox->put(&msg, token_size);
-      const auto* res = static_cast<std::string*>(my_mailbox->get());
+      const auto* res = my_mailbox->get<std::string>();
       XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str());
     } else {
-      auto* res = static_cast<std::string*>(my_mailbox->get());
+      auto* res = my_mailbox->get<std::string>();
       XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str());
       XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->get_cname());
       neighbor_mailbox->put(res, token_size);
index 65cc5fe..b65ea8e 100644 (file)
@@ -47,7 +47,7 @@ static void communication_rx_fun(std::vector<std::string> args)
   const char* host_name         = simgrid::s4u::this_actor::get_host()->get_cname();
   simgrid::s4u::Mailbox* mbox   = simgrid::s4u::Mailbox::by_name(args.at(0));
 
-  const auto* payload       = static_cast<struct s_payload*>(mbox->get());
+  const auto* payload       = mbox->get<struct s_payload>();
   double clock_end          = simgrid::s4u::Engine::get_clock();
 
   XBT_INFO("%s:%s to %s:%s => %g sec", payload->tx_host->get_cname(), payload->tx_actor_name, host_name, actor_name,
index ec1cf06..d51ebbd 100644 (file)
@@ -75,7 +75,7 @@ static void peer(int argc, char** argv)
   while (pending_finalize_messages > 0) {
     if (my_mbox->ready()) {
       double start                = simgrid::s4u::Engine::get_clock();
-      const auto* received        = static_cast<std::string*>(my_mbox->get());
+      const auto* received        = my_mbox->get<std::string>();
       double waiting_time         = simgrid::s4u::Engine::get_clock() - start;
       xbt_assert(
           waiting_time == 0,
index b0c7c8a..5377f38 100644 (file)
@@ -45,13 +45,10 @@ static void sender(int argc, char**)
 static void receiver(int, char**)
 {
   simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
-
   XBT_INFO("Wait for the message.");
-  void* payload = mbox->get();
+  const auto* received = mbox->get<std::string>();
 
-  const auto* received = static_cast<std::string*>(payload);
   XBT_INFO("I got '%s'.", received->c_str());
-
   delete received;
 }
 
index 2c2a60b..c9f04be 100644 (file)
@@ -89,7 +89,7 @@ public:
   {
     XBT_INFO("Wait for my first message");
     for (bool cont = true; cont;) {
-      const auto* received = static_cast<std::string*>(mbox->get());
+      const auto* received = mbox->get<std::string>();
       XBT_INFO("I got a '%s'.", received->c_str());
       cont = (*received != "finalize"); // If it's a finalize message, we're done
       // Receiving the message was all we were supposed to do
index 98b3e56..5d7f920 100644 (file)
@@ -102,7 +102,7 @@ public:
   {
     XBT_INFO("Wait for my first message");
     for (bool cont = true; cont;) {
-      const auto* received = static_cast<std::string*>(mbox->get());
+      const auto* received = mbox->get<std::string>();
       XBT_INFO("I got a '%s'.", received->c_str());
       cont = (*received != "finalize"); // If it's a finalize message, we're done
       // Receiving the message was all we were supposed to do
index 33597a4..957dce2 100644 (file)
@@ -71,7 +71,7 @@ static void receiver(int argc, char** argv)
 
   XBT_INFO("Wait for my first message");
   for (bool cont = true; cont;) {
-    const auto* received = static_cast<std::string*>(mbox->get());
+    const auto* received = mbox->get<std::string>();
     XBT_INFO("I got a '%s'.", received->c_str());
     if (*received == "finalize")
       cont = false; // If it's a finalize message, we're done.
index a44422e..f8da5b7 100644 (file)
@@ -49,7 +49,7 @@ static void receiver(std::vector<std::string> args)
   simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::string("message"));
 
   if (flow_amount == 1) {
-    void* res = mailbox->get();
+    char* res = mailbox->get<char>();
     xbt_free(res);
   } else {
     std::vector<void*> data(flow_amount);
index 1ecf5db..6d1bb89 100644 (file)
@@ -35,7 +35,7 @@ static void receiver()
   std::string mbName = "MailBoxRCV";
   XBT_INFO("RECEIVING on mb %s", mbName.c_str());
   simgrid::s4u::Mailbox *myBox = simgrid::s4u::Mailbox::by_name(mbName);
-  myBox->get();
+  myBox->get<std::string>();
 
   XBT_INFO("received all messages");
 }
index 593d192..af45373 100644 (file)
@@ -48,7 +48,7 @@ static void receiver()
 {
   ensure_other_tid();
 
-  const auto* payload = static_cast<std::string*>(simgrid::s4u::Mailbox::by_name("some mailbox")->get());
+  const auto* payload = simgrid::s4u::Mailbox::by_name("some mailbox")->get<std::string>();
   XBT_INFO("Task received");
   delete payload;
 }
index 935345a..f9bf0a1 100644 (file)
@@ -53,7 +53,7 @@ static void coordinator()
   simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("coordinator");
 
   while (true) {
-    m = static_cast<Message*>(mbox->get());
+    m = mbox->get<Message>();
     if (m->kind == Message::Kind::REQUEST) {
       if (CS_used) {
         XBT_INFO("CS already used. Queue the request.");
@@ -101,7 +101,7 @@ static void client(int id)
       XBT_INFO("Propositions changed : r=1, cs=0");
     }
 
-    const auto* grant = static_cast<Message*>(my_mailbox->get());
+    const auto* grant = my_mailbox->get<Message>();
 
     if ((id == 1) && (grant->kind == Message::Kind::GRANT)) {
       cs = 1;
index e642594..d192c08 100644 (file)
@@ -17,17 +17,17 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
 
 static void server()
 {
-  void* received = nullptr;
-  int count      = 0;
+  int* received = nullptr;
+  int count     = 0;
   while (count < N) {
     if (received) {
-      delete static_cast<int*>(received);
+      delete received;
       received = nullptr;
     }
-    received = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
+    received = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
     count++;
   }
-  int value_got = *(static_cast<int*>(received));
+  int value_got = *received;
   MC_assert(value_got == 3);
 
   XBT_INFO("OK");
index 6555885..77b495c 100644 (file)
@@ -15,27 +15,27 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
 
 static void server()
 {
-  void* received1 = nullptr;
-  void* received2 = nullptr;
+  int* received1 = nullptr;
+  int* received2 = nullptr;
 
-  received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
-  long val1 = *(static_cast<int*>(received1));
+  received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
+  long val1 = *received1;
   received1 = nullptr;
   XBT_INFO("Received %ld", val1);
 
-  received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
-  long val2 = *(static_cast<int*>(received2));
+  received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
+  long val2 = *received2;
   received2 = nullptr;
   XBT_INFO("Received %ld", val2);
 
   MC_assert(std::min(val1, val2) == 1);
 
-  received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
-  val1      = *(static_cast<int*>(received1));
+  received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
+  val1      = *received1;
   XBT_INFO("Received %ld", val1);
 
-  received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
-  val2      = *(static_cast<int*>(received2));
+  received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
+  val2      = *received2;
   XBT_INFO("Received %ld", val2);
 
   XBT_INFO("OK");
index fb78611..aaeb29b 100644 (file)
@@ -18,7 +18,7 @@ static int server(int worker_amount)
   int value_got             = -1;
   simgrid::s4u::Mailbox* mb = simgrid::s4u::Mailbox::by_name("server");
   for (int count = 0; count < worker_amount; count++) {
-    const auto* msg = static_cast<int*>(mb->get());
+    const auto* msg = mb->get<int>();
     value_got = *msg;
     delete msg;
   }
index f397ade..8600357 100644 (file)
@@ -29,7 +29,7 @@ static void sender(std::string mailbox, double msg_size, unsigned sleep_time)
 static void receiver(std::string mailbox)
 {
   auto* mbox = simgrid::s4u::Mailbox::by_name(mailbox);
-  auto msg   = std::unique_ptr<Message>(static_cast<Message*>(mbox->get()));
+  auto msg   = std::unique_ptr<Message>(mbox->get<Message>());
   XBT_INFO("[%s] %s received %d bytes from %s",
            mailbox.c_str(),
            simgrid::s4u::this_actor::get_host()->get_name().c_str(),
index 83e4f0a..fca75f9 100644 (file)
@@ -72,7 +72,7 @@ static void worker(int argc, char* argv[])
 
   XBT_DEBUG("Worker started");
 
-  const auto* payload = static_cast<double*>(mbox->get());
+  const auto* payload = mbox->get<double>();
 
   count_finished--;
   if (count_finished == 0) {
index d8c406c..dab6776 100644 (file)
@@ -21,7 +21,7 @@ static void sender(simgrid::s4u::Mailbox* mailbox, int data_size)
 static void receiver(simgrid::s4u::Mailbox* mailbox)
 {
   XBT_INFO("Wait for a message.");
-  mailbox->get();
+  mailbox->get<std::string>();
   XBT_INFO("Done.");
 }
 
index e0d6ba3..1927cdb 100644 (file)
@@ -76,7 +76,7 @@ static void worker(std::vector<std::string> args)
   while (true) {
     try {
       XBT_INFO("Waiting a message on %s", mailbox->get_cname());
-      const auto* payload = static_cast<double*>(mailbox->get());
+      const auto* payload = mailbox->get<double>();
       xbt_assert(payload != nullptr, "mailbox->get() failed");
       double comp_size = *payload;
       delete payload;
index 10437a7..f4921d5 100644 (file)
@@ -11,13 +11,14 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example")
 static void sender(const std::string& mailbox, uint64_t msg_size)
 {
   auto mbox = simgrid::s4u::Mailbox::by_name(mailbox);
-  mbox->put((void*)1, msg_size);
+  static int payload = 42;
+  mbox->put(&payload, msg_size);
 }
 
 static void receiver(const std::string& mailbox)
 {
   auto mbox = simgrid::s4u::Mailbox::by_name(mailbox);
-  mbox->get();
+  mbox->get<int>();
 }
 
 static void run_transfer(simgrid::s4u::Host* src_host, simgrid::s4u::Host* dst_host, const std::string& mailbox,
index e04bd78..ec4781c 100644 (file)
@@ -71,7 +71,7 @@ public:
 
     ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME.c_str(), simgrid::s4u::this_actor::get_cname(),
               from->get_cname());
-    delete static_cast<std::string*>(from->get());
+    delete from->get<std::string>();
     log_action(action, simgrid::s4u::Engine::get_clock() - clock);
   }
 };
index 921fe60..dd8176b 100644 (file)
@@ -39,7 +39,7 @@ static void worker()
 {
   auto mbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
   while (true) {
-    const auto* task = static_cast<Task*>(mbox->get());
+    const auto* task = mbox->get<Task>();
     if (task->name == "finalize") {
       delete task;
       break;
index d0013cd..509cb58 100644 (file)
@@ -59,7 +59,7 @@ static void worker(std::vector<std::string> args)
   TRACE_host_variable_set(my_hostname, "task_computation", 0);
 
   while (true) {
-    const auto* task = static_cast<Task*>(mailbox->get());
+    const auto* task = mailbox->get<Task>();
     if (task->name == "finalize") {
       delete task;
       break;
index fd8d3d3..7e77660 100644 (file)
@@ -20,7 +20,7 @@ static void emigrant()
   simgrid::s4u::this_actor::sleep_for(2);
 
   while (true) { // I am an eternal emigrant
-    auto destination = std::unique_ptr<std::string>(static_cast<std::string*>(mailbox->get()));
+    auto destination = std::unique_ptr<std::string>(mailbox->get<std::string>());
     if (destination->empty())
       break; // there is no destination, die
     simgrid::s4u::this_actor::set_host(simgrid::s4u::Host::by_name(*destination));
index c81e697..5c12042 100644 (file)
@@ -51,7 +51,7 @@ static void worker(std::vector<std::string> args)
 
   double compute_cost;
   do {
-    const auto* msg   = static_cast<double*>(mailbox->get());
+    const auto* msg   = mailbox->get<double>();
     compute_cost      = *msg;
     delete msg;
 
index fc492d5..ce60453 100644 (file)
@@ -251,7 +251,7 @@ PYBIND11_MODULE(simgrid, m)
       .def(
           "get",
           [](Mailbox* self) {
-            py::object data = pybind11::reinterpret_steal<py::object>(static_cast<PyObject*>(self->get()));
+            py::object data = pybind11::reinterpret_steal<py::object>(self->get<PyObject>());
             // data.dec_ref(); // FIXME: why does it break python-actor-create?
             return data;
           },
index 87195a5..65bc4e5 100644 (file)
@@ -30,7 +30,7 @@ void MigrationRx::operator()()
       std::string("__mig_stage3:") + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" + dst_pm_->get_cname() + ")";
 
   while (not received_finalize) {
-    const std::string* payload = static_cast<std::string*>(mbox->get());
+    const std::string* payload = mbox->get<std::string>();
 
     if (finalize_task_name == *payload)
       received_finalize = true;
@@ -353,7 +353,7 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm)
   XBT_DEBUG("wait for reception of the final ACK (i.e. migration has been correctly performed");
   simgrid::s4u::Mailbox* mbox_ctl = simgrid::s4u::Mailbox::by_name(
       std::string("__mbox_mig_ctl:") + vm->get_cname() + "(" + src_pm->get_cname() + "-" + dst_pm->get_cname() + ")");
-  delete static_cast<std::string*>(mbox_ctl->get());
+  delete mbox_ctl->get<std::string>();
   tx->join();
   rx->join();
 
index c248790..56c0603 100644 (file)
@@ -31,11 +31,11 @@ static int receiver(const char* box_name)
   auto mb = simgrid::s4u::Mailbox::by_name(box_name);
   const int* payload;
 
-  payload = static_cast<int*>(mb->get());
+  payload = mb->get<int>();
   MC_assert(*payload == 1);
   delete payload;
 
-  payload = static_cast<int*>(mb->get());
+  payload = mb->get<int>();
   MC_assert(*payload == 2);
   delete payload;
 
index bbcfbd7..9dc9347 100644 (file)
@@ -31,7 +31,7 @@ static void test_link_off_helper(double delay)
       simgrid::s4u::this_actor::sleep_until(milestone[i]);
       REQUIRE_NETWORK_FAILURE({
         INFO("get(" << ('A' + i) << ")");
-        simgrid::s4u::Mailbox::by_name("mb")->get();
+        simgrid::s4u::Mailbox::by_name("mb")->get<int>();
       });
     }
     simgrid::s4u::this_actor::sleep_until(milestone[4]);
@@ -89,7 +89,7 @@ TEST_CASE("Activity lifecycle: comm activities")
 
     simgrid::s4u::Actor::create("receiver", all_hosts[2], [&recv_done]() {
       assert_exit(true, 5);
-      void* payload = simgrid::s4u::Mailbox::by_name("mb")->get();
+      char* payload = simgrid::s4u::Mailbox::by_name("mb")->get<char>();
       xbt_free(payload);
       recv_done = true;
     });
@@ -118,7 +118,7 @@ TEST_CASE("Activity lifecycle: comm activities")
     simgrid::s4u::Actor::create("receiver", all_hosts[2], [&recv_done]() {
       assert_exit(true, 3);
       simgrid::s4u::this_actor::sleep_for(2);
-      void* payload = simgrid::s4u::Mailbox::by_name("mb")->get();
+      char* payload = simgrid::s4u::Mailbox::by_name("mb")->get<char>();
       xbt_free(payload);
       recv_done = true;
     });
@@ -148,7 +148,7 @@ TEST_CASE("Activity lifecycle: comm activities")
 
     simgrid::s4u::Actor::create("receiver", all_hosts[2], [&recv_done]() {
       assert_exit(true, 3);
-      void* payload = simgrid::s4u::Mailbox::by_name("mb")->get();
+      char* payload = simgrid::s4u::Mailbox::by_name("mb")->get<char>();
       xbt_free(payload);
       recv_done = true;
     });
@@ -181,7 +181,7 @@ TEST_CASE("Activity lifecycle: comm activities")
     simgrid::s4u::Actor::create("receiver", all_hosts[2], [&recv_done]() {
       assert_exit(true, 2);
       REQUIRE_NETWORK_FAILURE({
-        void* payload = simgrid::s4u::Mailbox::by_name("mb")->get();
+        char* payload = simgrid::s4u::Mailbox::by_name("mb")->get<char>();
         xbt_free(payload);
       });
       recv_done = true;
@@ -213,7 +213,7 @@ TEST_CASE("Activity lifecycle: comm activities")
                                                                &in_catch_before_on_exit, &in_catch_after_on_exit]() {
           assert_exit(false, 1);
           try {
-            simgrid::s4u::Mailbox::by_name("mb")->get();
+            simgrid::s4u::Mailbox::by_name("mb")->get<int>();
           } catch (simgrid::NetworkFailureException const&) {
             // Shouldn't get in here after the on_exit function
             in_catch_before_on_exit = not in_on_exit;
index 3e82259..73b5336 100644 (file)
@@ -22,7 +22,7 @@ public:
   {
     XBT_INFO("Starting.");
     auto mailbox = simgrid::s4u::Mailbox::by_name("receiver");
-    int data     = *(int*)mailbox->get();
+    int data     = *mailbox->get<int>();
     XBT_INFO("Got %d at the end", data);
   }
 };
index fc2ca66..c9282f0 100644 (file)
@@ -94,58 +94,57 @@ static void receiver(std::vector<std::string> args)
   XBT_INFO("Receiver spec: %s", args[0].c_str());
   for (unsigned int test = 1; test <= args[0].size(); test++) {
     simgrid::s4u::this_actor::sleep_until(test * 5 - 5);
-    std::string mboxName          = "Test #" + std::to_string(test);
-    simgrid::s4u::Mailbox* mbox   = simgrid::s4u::Mailbox::by_name(mboxName);
-    void* received                = nullptr;
+    std::string mboxName        = "Test #" + std::to_string(test);
+    simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+    std::string* received       = nullptr;
 
     switch (args[0][test - 1]) {
       case 'r':
         XBT_INFO("Test %u: r (regular receive)", test);
-        received = mbox->get();
+        received = mbox->get<std::string>();
         break;
       case 'R':
         XBT_INFO("Test %u: R (sleep + regular receive)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
-        received = mbox->get();
+        received = mbox->get<std::string>();
         break;
 
       case 'i':
         XBT_INFO("Test %u: i (asynchronous irecv)", test);
-        mbox->get_async(&received)->wait();
+        mbox->get_async<std::string>(&received)->wait();
         break;
       case 'I':
         XBT_INFO("Test %u: I (sleep + asynchronous irecv)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
-        mbox->get_async(&received)->wait();
+        mbox->get_async<std::string>(&received)->wait();
         break;
       case 'p':
         XBT_INFO("Test %u: p (regular receive on permanent mailbox)", test);
         mbox->set_receiver(simgrid::s4u::Actor::self());
-        received = mbox->get();
+        received = mbox->get<std::string>();
         break;
       case 'P':
         XBT_INFO("Test %u: P (sleep + regular receive on permanent mailbox)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
         mbox->set_receiver(simgrid::s4u::Actor::self());
-        received = mbox->get();
+        received = mbox->get<std::string>();
         break;
       case 'j':
         XBT_INFO("Test %u: j (irecv on permanent mailbox)", test);
         mbox->set_receiver(simgrid::s4u::Actor::self());
-        mbox->get_async(&received)->wait();
+        mbox->get_async<std::string>(&received)->wait();
         break;
       case 'J':
         XBT_INFO("Test %u: J (sleep + irecv on permanent mailbox)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
         mbox->set_receiver(simgrid::s4u::Actor::self());
-        mbox->get_async(&received)->wait();
+        mbox->get_async<std::string>(&received)->wait();
         break;
       default:
         xbt_die("Unknown receiver spec for test %u: '%c'", test, args[0][test - 1]);
     }
-    const std::string* receivedStr = static_cast<std::string*>(received);
-    xbt_assert(*receivedStr == mboxName);
-    delete receivedStr;
+    xbt_assert(*received == mboxName);
+    delete received;
     XBT_INFO("Test %u OK", test);
   }
   simgrid::s4u::this_actor::sleep_for(0.5);
index 8f12f85..011b7e8 100644 (file)
@@ -43,7 +43,7 @@ static void commRX()
   const std::string* payload = nullptr;
   XBT_INFO("  Start RX");
   try {
-    payload = static_cast<std::string*>(simgrid::s4u::Mailbox::by_name("comm")->get());
+    payload = simgrid::s4u::Mailbox::by_name("comm")->get<std::string>();
     XBT_INFO("  Receive message: %s", payload->c_str());
   } catch (const simgrid::HostFailureException&) {
     XBT_INFO("  Receive message: HOST_FAILURE");
index 69f62bf..bb98a89 100644 (file)
@@ -40,7 +40,7 @@ static void worker()
 
   XBT_INFO("Worker receiving");
   try {
-    payload = static_cast<std::string*>(mailbox->get());
+    payload = mailbox->get<std::string>();
   } catch (const simgrid::HostFailureException&) {
     XBT_DEBUG("The host has been turned off, this was expected");
     delete payload;
index ee5cfe1..805f34a 100644 (file)
@@ -15,7 +15,7 @@ static void worker()
 
   while (true) {
     try {
-      payload = static_cast<std::string*>(mailbox->get());
+      payload = mailbox->get<std::string>();
     } catch (const simgrid::HostFailureException&) {
       XBT_DEBUG("The host has been turned off, this was expected");
       return;
index e277a3d..04e7ac4 100644 (file)
@@ -24,7 +24,7 @@ static void server()
   XBT_INFO("Mailbox::listen_from() returns %ld (should return my pid, which is %ld)", mailbox->listen_from(),
            simgrid::s4u::this_actor::get_pid());
 
-  const std::string* res = static_cast<std::string*>(mailbox->get());
+  const std::string* res = mailbox->get<std::string>();
 
   xbt_assert(*res == "Some data", "Data received: %s", res->c_str());
   XBT_INFO("Data successfully received from regular mailbox");
@@ -39,7 +39,7 @@ static void server()
   xbt_assert(mailbox2->listen()); // used to break.
   XBT_INFO("Task listen works on asynchronous mailboxes");
 
-  res = static_cast<std::string*>(mailbox2->get());
+  res = mailbox2->get<std::string>();
   xbt_assert(*res == "More data");
   delete res;
 
index 22bc946..c9aa53d 100644 (file)
@@ -33,7 +33,7 @@ static void test_receive()
 {
   for (int nb_message = 0; nb_message < nb_message_to_send * nb_sender; nb_message++) {
     XBT_VERB("waiting for messages");
-    int* ptr = (int*)(box->get());
+    int* ptr = box->get<int>();
     int id   = *ptr;
     XBT_VERB("received messages #%i", id);
     delete ptr;
index fac6475..c05e9cc 100644 (file)
@@ -33,7 +33,7 @@ static void test_send(){
 static void test_receive(){
   for (int nb_message = 0; nb_message < nb_message_to_send * nb_sender; nb_message++) {
     XBT_VERB("waiting for messages");
-    int* ptr = (int*)(box->get());
+    int* ptr = box->get<int>();
     int id   = *ptr;
     XBT_VERB("received messages #%i", id);
     delete ptr;
index f8e2571..d9e79d8 100644 (file)
@@ -25,7 +25,7 @@ static void killall()
 {
   simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("mailbox");
   for (int i = 0; i < 3; i++) {
-    const auto* pid = static_cast<aid_t*>(mailbox->get());
+    const auto* pid = mailbox->get<aid_t>();
     XBT_INFO("Killing process \"%ld\".", *pid);
     simgrid::s4u::Actor::by_pid(*pid)->kill();
   }
index 39b0195..d676ff5 100644 (file)
@@ -127,7 +127,7 @@ static void server()
 
   XBT_INFO("Server waiting for transfers ...");
   while (true) {
-    const std::string* msg = static_cast<std::string*>(mailbox->get());
+    const std::string* msg = mailbox->get<std::string>();
     if (*msg == "finalize") { // Shutdown ...
       delete msg;
       break;
index 9a4ac17..0a21fdd 100644 (file)
@@ -71,7 +71,8 @@ void run_ping_test(const char* src, const char* dest, int data_size)
     XBT_INFO("Actual result: Sending %d bytes from '%s' to '%s' takes %f seconds.", data_size,
              simgrid::s4u::this_actor::get_host()->get_cname(), dest, end_time - start_time);
   });
-  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name(dest), [mailbox]() { mailbox->get(); });
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name(dest),
+                              [mailbox]() { mailbox->get<std::string>(); });
   const auto* ap1 = simgrid::s4u::Link::by_name("AP1");
   ap1->set_host_wifi_rate(simgrid::s4u::Host::by_name(src), 0);
   ap1->set_host_wifi_rate(simgrid::s4u::Host::by_name(dest), 0);
index 444bfac..bdebfb3 100644 (file)
@@ -75,7 +75,8 @@ void run_ping_test(const char* src, const char* dest, int data_size)
     XBT_INFO("Actual result: Sending %d bytes from '%s' to '%s' takes %f seconds.", data_size,
              simgrid::s4u::this_actor::get_host()->get_cname(), dest, end_time - start_time);
   });
-  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name(dest), [mailbox]() { mailbox->get(); });
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name(dest),
+                              [mailbox]() { mailbox->get<std::string>(); });
   auto* l = (simgrid::kernel::resource::NetworkWifiLink*)simgrid::s4u::Link::by_name("AP1")->get_impl();
   if(!l->toggle_decay_model())
     l->toggle_decay_model();