Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Concatenate nested namespaces (sonar).
[simgrid.git] / src / msg / msg_comm.cpp
index 3bbc4c3..049c669 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2004-2022. 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. */
 #include "src/instr/instr_private.hpp"
 #include "src/msg/msg_private.hpp"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_comm, msg, "Logging specific to MSG (comm)");
-
-namespace simgrid {
-namespace msg {
+namespace simgrid::msg {
 
 bool Comm::test()
 {
@@ -62,8 +59,7 @@ msg_error_t Comm::wait_for(double timeout)
 
   return status_;
 }
-} // namespace msg
-} // namespace simgrid
+} // namespace simgrid::msg
 
 /**
  * @brief Checks whether a communication is done, and if yes, finalizes it.
@@ -84,30 +80,29 @@ int MSG_comm_test(msg_comm_t comm)
  * @return the position of the finished communication if any
  * (but it may have failed, use MSG_comm_get_status() to know its status), or -1 if none is finished
  */
-int MSG_comm_testany(xbt_dynar_t comms)
+int MSG_comm_testany(const_xbt_dynar_t comms)
 {
-  int finished_index = -1;
+  ssize_t finished_index = -1;
 
   /* Create the equivalent array with SIMIX objects: */
-  std::vector<simgrid::kernel::activity::CommImpl*> s_comms;
+  std::vector<simgrid::s4u::CommPtr> s_comms;
   s_comms.reserve(xbt_dynar_length(comms));
   msg_comm_t comm;
   unsigned int cursor;
-  xbt_dynar_foreach (comms, cursor, comm) {
-    s_comms.push_back(static_cast<simgrid::kernel::activity::CommImpl*>(comm->s_comm->get_impl()));
-  }
+  xbt_dynar_foreach (comms, cursor, comm)
+    s_comms.push_back(comm->s_comm);
 
   msg_error_t status = MSG_OK;
   try {
-    finished_index = simcall_comm_testany(s_comms.data(), s_comms.size());
+    finished_index = simgrid::s4u::Comm::test_any(s_comms);
   } catch (const simgrid::TimeoutException& e) {
-    finished_index = e.value;
+    finished_index = e.get_value();
     status         = MSG_TIMEOUT;
   } catch (const simgrid::CancelException& e) {
-    finished_index = e.value;
+    finished_index = e.get_value();
     status         = MSG_TASK_CANCELED;
   } catch (const simgrid::NetworkFailureException& e) {
-    finished_index = e.value;
+    finished_index = e.get_value();
     status         = MSG_TRANSFER_FAILURE;
   }
 
@@ -122,11 +117,11 @@ int MSG_comm_testany(xbt_dynar_t comms)
     }
   }
 
-  return finished_index;
+  return static_cast<int>(finished_index);
 }
 
 /** @brief Destroys the provided communication. */
-void MSG_comm_destroy(msg_comm_t comm)
+void MSG_comm_destroy(const_msg_comm_t comm)
 {
   delete comm;
 }
@@ -161,30 +156,30 @@ void MSG_comm_waitall(msg_comm_t* comm, int nb_elem, double timeout)
  * @return the position of the first finished communication
  * (but it may have failed, use MSG_comm_get_status() to know its status)
  */
-int MSG_comm_waitany(xbt_dynar_t comms)
+int MSG_comm_waitany(const_xbt_dynar_t comms)
 {
-  int finished_index = -1;
+  ssize_t finished_index = -1;
 
   /* Create the equivalent array with SIMIX objects: */
-  std::vector<simgrid::kernel::activity::CommImpl*> s_comms;
+  std::vector<simgrid::s4u::CommPtr> s_comms;
   s_comms.reserve(xbt_dynar_length(comms));
   msg_comm_t comm;
   unsigned int cursor;
   xbt_dynar_foreach (comms, cursor, comm) {
-    s_comms.push_back(static_cast<simgrid::kernel::activity::CommImpl*>(comm->s_comm->get_impl()));
+    s_comms.push_back(comm->s_comm);
   }
 
   msg_error_t status = MSG_OK;
   try {
-    finished_index = simcall_comm_waitany(s_comms.data(), s_comms.size(), -1);
+    finished_index = simgrid::s4u::Comm::wait_any_for(s_comms, -1);
   } catch (const simgrid::TimeoutException& e) {
-    finished_index = e.value;
+    finished_index = e.get_value();
     status         = MSG_TIMEOUT;
   } catch (const simgrid::CancelException& e) {
-    finished_index = e.value;
+    finished_index = e.get_value();
     status         = MSG_TASK_CANCELED;
   } catch (const simgrid::NetworkFailureException& e) {
-    finished_index = e.value;
+    finished_index = e.get_value();
     status         = MSG_TRANSFER_FAILURE;
   }
 
@@ -199,7 +194,7 @@ int MSG_comm_waitany(xbt_dynar_t comms)
     (*comm->task_received)->set_not_used();
   }
 
-  return finished_index;
+  return static_cast<int>(finished_index);
 }
 
 /**
@@ -207,9 +202,8 @@ int MSG_comm_waitany(xbt_dynar_t comms)
  * @param comm a finished communication
  * @return the status of the communication, or #MSG_OK if no error occurred during the communication
  */
-msg_error_t MSG_comm_get_status(msg_comm_t comm)
+msg_error_t MSG_comm_get_status(const_msg_comm_t comm)
 {
-
   return comm->get_status();
 }
 
@@ -218,27 +212,9 @@ msg_error_t MSG_comm_get_status(msg_comm_t comm)
  * @param comm the communication where to get the task
  * @return the task from the communication
  */
-msg_task_t MSG_comm_get_task(msg_comm_t comm)
+msg_task_t MSG_comm_get_task(const_msg_comm_t comm)
 {
   xbt_assert(comm, "Invalid parameter");
 
   return comm->task_received ? *comm->task_received : comm->task_sent;
 }
-
-/**
- * @brief This function is called by SIMIX in kernel mode to copy the data of a comm.
- * @param comm the comm
- * @param buff the data copied
- * @param buff_size size of the buffer
- */
-// deprecated but used by MSG_set_copy_callback. Should be removed in v325
-void MSG_comm_copy_data_from_SIMIX(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
-{
-  SIMIX_comm_copy_pointer_callback(comm, buff, buff_size);
-
-  // notify the user callback if any
-  if (msg_global->task_copy_callback) {
-    msg_task_t task = static_cast<msg_task_t>(buff);
-    msg_global->task_copy_callback(task, comm->src_actor_->ciface(), comm->dst_actor_->ciface());
-  }
-}