Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sonar
[simgrid.git] / src / msg / msg_gos.cpp
index 62bed03..3c8121b 100644 (file)
@@ -3,7 +3,7 @@
 /* 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 <xbt/ex.hpp>
+#include "simgrid/Exception.hpp"
 
 #include "simgrid/s4u/Mailbox.hpp"
 #include "src/instr/instr_private.hpp"
@@ -65,33 +65,28 @@ msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeo
               task->name ?: "", simdata->host_nb, simdata->host_list, simdata->flops_parallel_amount,
               simdata->bytes_parallel_amount, -1.0, timeout));
       XBT_DEBUG("Parallel execution action created: %p", simdata->compute.get());
+      if (task->category != nullptr)
+        simcall_set_category(simdata->compute, task->category);
     } else {
       simdata->compute = boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(
-          simcall_execution_start(task->name ?: "", simdata->flops_amount, simdata->priority, simdata->bound,
-                                  MSG_process_get_host(MSG_process_self())));
+          simcall_execution_start(task->name ?: "", task->category ?: "", simdata->flops_amount, simdata->priority,
+                                  simdata->bound, MSG_process_get_host(MSG_process_self())));
     }
-    if (task->category != nullptr)
-      simcall_set_category(simdata->compute, task->category);
+
     comp_state = simcall_execution_wait(simdata->compute);
 
     simdata->setNotUsed();
 
     XBT_DEBUG("Execution task '%s' finished in state %d", task->name, (int)comp_state);
-  }
-  catch (xbt_ex& e) {
-    switch (e.category) {
-    case cancel_error:
+  } catch (simgrid::HostFailureException& e) {
+    status = MSG_HOST_FAILURE;
+  } catch (simgrid::TimeoutError& e) {
+    status = MSG_TIMEOUT;
+  } catch (xbt_ex& e) {
+    if (e.category == cancel_error)
       status = MSG_TASK_CANCELED;
-      break;
-    case host_error:
-      status = MSG_HOST_FAILURE;
-      break;
-    case timeout_error:
-      status = MSG_TIMEOUT;
-      break;
-    default:
+    else
       throw;
-    }
   }
 
   /* action ended, set comm and compute = nullptr, the actions is already destroyed in the main function */
@@ -116,8 +111,9 @@ msg_error_t MSG_process_sleep(double nb_sec)
 
   try {
     simgrid::s4u::this_actor::sleep_for(nb_sec);
-  }
-  catch(xbt_ex& e) {
+  } catch (simgrid::HostFailureException& e) {
+    status = MSG_HOST_FAILURE;
+  } catch (xbt_ex& e) {
     if (e.category == cancel_error) {
       XBT_DEBUG("According to the JAVA API, a sleep call should only deal with HostFailureException, I'm lost.");
       // adsein: MSG_TASK_CANCELED is assigned when someone kills the process that made the sleep, this is not
@@ -279,19 +275,18 @@ msg_error_t MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, d
                       timeout, rate);
     XBT_DEBUG("Got task %s from %s", (*task)->name, mailbox->get_cname());
     (*task)->simdata->setNotUsed();
-  }
-  catch (xbt_ex& e) {
+  } catch (simgrid::HostFailureException& e) {
+    ret = MSG_HOST_FAILURE;
+  } catch (simgrid::TimeoutError& e) {
+    ret = MSG_TIMEOUT;
+  } catch (xbt_ex& e) {
     switch (e.category) {
-    case host_error:
     case cancel_error:
       ret = MSG_HOST_FAILURE;
       break;
     case network_error:
       ret = MSG_TRANSFER_FAILURE;
       break;
-    case timeout_error:
-      ret = MSG_TIMEOUT;
-      break;
     default:
       throw;
     }
@@ -483,19 +478,16 @@ int MSG_comm_test(msg_comm_t comm)
       /* I am the receiver */
       (*comm->task_received)->simdata->setNotUsed();
     }
+  } catch (simgrid::TimeoutError& e) {
+    comm->status = MSG_TIMEOUT;
+    finished     = true;
   }
   catch (xbt_ex& e) {
-    switch (e.category) {
-      case network_error:
-        comm->status = MSG_TRANSFER_FAILURE;
-        finished     = true;
-        break;
-      case timeout_error:
-        comm->status = MSG_TIMEOUT;
-        finished     = true;
-        break;
-      default:
-        throw;
+    if (e.category == network_error) {
+      comm->status = MSG_TRANSFER_FAILURE;
+      finished     = true;
+    } else {
+      throw;
     }
   }
 
@@ -525,6 +517,9 @@ int MSG_comm_testany(xbt_dynar_t comms)
   msg_error_t status = MSG_OK;
   try {
     finished_index = simcall_comm_testany(s_comms.data(), s_comms.size());
+  } catch (simgrid::TimeoutError& e) {
+    finished_index = e.value;
+    status         = MSG_TIMEOUT;
   }
   catch (xbt_ex& e) {
     switch (e.category) {
@@ -532,10 +527,6 @@ int MSG_comm_testany(xbt_dynar_t comms)
         finished_index = e.value;
         status = MSG_TRANSFER_FAILURE;
         break;
-      case timeout_error:
-        finished_index = e.value;
-        status = MSG_TIMEOUT;
-        break;
       default:
         throw;
     }
@@ -584,18 +575,14 @@ msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
     }
 
     /* FIXME: these functions are not traceable */
+  } catch (simgrid::TimeoutError& e) {
+    comm->status = MSG_TIMEOUT;
   }
   catch (xbt_ex& e) {
-    switch (e.category) {
-    case network_error:
+    if (e.category == network_error)
       comm->status = MSG_TRANSFER_FAILURE;
-      break;
-    case timeout_error:
-      comm->status = MSG_TIMEOUT;
-      break;
-    default:
+    else
       throw;
-    }
   }
 
   return comm->status;
@@ -638,19 +625,16 @@ int MSG_comm_waitany(xbt_dynar_t comms)
   msg_error_t status = MSG_OK;
   try {
     finished_index = simcall_comm_waitany(s_comms, -1);
+  } catch (simgrid::TimeoutError& e) {
+    finished_index = e.value;
+    status         = MSG_TIMEOUT;
   }
   catch(xbt_ex& e) {
-    switch (e.category) {
-      case network_error:
-        finished_index = e.value;
-        status = MSG_TRANSFER_FAILURE;
-        break;
-      case timeout_error:
-        finished_index = e.value;
-        status = MSG_TIMEOUT;
-        break;
-      default:
-        throw;
+    if (e.category == network_error) {
+      finished_index = e.value;
+      status         = MSG_TRANSFER_FAILURE;
+    } else {
+      throw;
     }
   }
 
@@ -797,6 +781,8 @@ msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, doubl
       simcall_set_category(comm, task->category);
     t_simdata->comm = boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(comm);
     simcall_comm_wait(comm, timeout);
+  } catch (simgrid::TimeoutError& e) {
+    ret = MSG_TIMEOUT;
   }
   catch (xbt_ex& e) {
     switch (e.category) {
@@ -806,9 +792,6 @@ msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, doubl
     case network_error:
       ret = MSG_TRANSFER_FAILURE;
       break;
-    case timeout_error:
-      ret = MSG_TIMEOUT;
-      break;
     default:
       throw;
     }