Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
keep a return value for MSG_process_sleep
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 12 Feb 2019 15:56:09 +0000 (16:56 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 12 Feb 2019 15:56:09 +0000 (16:56 +0100)
handle the exception in msg_legacy.cpp

include/simgrid/msg.h
src/msg/msg_legacy.cpp
teshsuite/msg/host_on_off_processes/host_on_off_processes.cpp

index 4cedf6e..97087ae 100644 (file)
@@ -44,6 +44,20 @@ typedef struct msg_Comm sg_msg_Comm;
 extern "C" {
 #endif
 
 extern "C" {
 #endif
 
+/** @brief Return code of most MSG functions */
+/* Keep these code as binary values: java bindings manipulate | of these values */
+typedef enum {
+  MSG_OK               = 0, /**< @brief Everything is right. Keep on going this way ! */
+  MSG_TIMEOUT          = 1, /**< @brief nothing good happened before the timer you provided elapsed */
+  MSG_TRANSFER_FAILURE = 2, /**< @brief There has been a problem during you task
+    transfer. Either the network is down or the remote host has been
+    shutdown. */
+  MSG_HOST_FAILURE = 4,     /**< @brief System shutdown. The host on which you are
+    running has just been rebooted. Free your datastructures and
+    return now !*/
+  MSG_TASK_CANCELED = 8     /**< @brief Canceled task. This task has been canceled by somebody!*/
+} msg_error_t;
+
 /* *************************** Network Zones ******************************** */
 #define msg_as_t msg_netzone_t /* portability macro */
 
 /* *************************** Network Zones ******************************** */
 #define msg_as_t msg_netzone_t /* portability macro */
 
@@ -210,7 +224,7 @@ XBT_PUBLIC void MSG_process_set_kill_time(msg_process_t process, double kill_tim
 /** @brief Yield the current actor; let the other actors execute first */
 XBT_PUBLIC void MSG_process_yield();
 /*** @brief Sleep for the specified number of seconds */
 /** @brief Yield the current actor; let the other actors execute first */
 XBT_PUBLIC void MSG_process_yield();
 /*** @brief Sleep for the specified number of seconds */
-XBT_PUBLIC void MSG_process_sleep(double nb_sec);
+XBT_PUBLIC msg_error_t MSG_process_sleep(double nb_sec);
 
 /** @brief Object representing an ongoing communication between processes.
  *
 
 /** @brief Object representing an ongoing communication between processes.
  *
@@ -245,20 +259,6 @@ typedef struct msg_task* msg_task_t;
 /** @brief Default value for an uninitialized #msg_task_t. */
 #define MSG_TASK_UNINITIALIZED NULL
 
 /** @brief Default value for an uninitialized #msg_task_t. */
 #define MSG_TASK_UNINITIALIZED NULL
 
-/** @brief Return code of most MSG functions */
-/* Keep these code as binary values: java bindings manipulate | of these values */
-typedef enum {
-  MSG_OK = 0,                 /**< @brief Everything is right. Keep on going this way ! */
-  MSG_TIMEOUT = 1,            /**< @brief nothing good happened before the timer you provided elapsed */
-  MSG_TRANSFER_FAILURE = 2,   /**< @brief There has been a problem during you task
-      transfer. Either the network is down or the remote host has been
-      shutdown. */
-  MSG_HOST_FAILURE = 4,       /**< @brief System shutdown. The host on which you are
-      running has just been rebooted. Free your datastructures and
-      return now !*/
-  MSG_TASK_CANCELED = 8      /**< @brief Canceled task. This task has been canceled by somebody!*/
-} msg_error_t;
-
 /************************** Global ******************************************/
 /** @brief set a configuration variable
  *
 /************************** Global ******************************************/
 /** @brief set a configuration variable
  *
index 38bc2ae..7636c9d 100644 (file)
@@ -3,6 +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. */
 
 /* 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 "simgrid/Exception.hpp"
 #include "src/msg/msg_private.hpp"
 
 #define MSG_CALL(type, oldname, args)
 #include "src/msg/msg_private.hpp"
 
 #define MSG_CALL(type, oldname, args)
@@ -123,9 +124,15 @@ void MSG_process_yield()
 {
   sg_actor_yield();
 }
 {
   sg_actor_yield();
 }
-void MSG_process_sleep(double duration)
-{
-  sg_actor_sleep_for(duration);
+
+msg_error_t MSG_process_sleep(double duration)
+{
+  try {
+    sg_actor_sleep_for(duration);
+    return MSG_OK;
+  } catch (simgrid::HostFailureException& e) {
+    return MSG_HOST_FAILURE;
+  }
 }
 /* ************************** NetZones *************************** */
 sg_netzone_t MSG_zone_get_root()
 }
 /* ************************** NetZones *************************** */
 sg_netzone_t MSG_zone_get_root()
index 242697b..3f500b0 100644 (file)
@@ -46,9 +46,8 @@ static int commTX(int /*argc*/, char** /*argv*/)
   msg_task_t task = MSG_task_create("COMM", 0, 100000000, NULL);
   MSG_task_dsend(task, mailbox, task_cleanup_handler);
   // We should wait a bit (if not the process will end before the communication, hence an exception on the other side).
   msg_task_t task = MSG_task_create("COMM", 0, 100000000, NULL);
   MSG_task_dsend(task, mailbox, task_cleanup_handler);
   // We should wait a bit (if not the process will end before the communication, hence an exception on the other side).
-  try {
-    MSG_process_sleep(30);
-  } catch (simgrid::HostFailureException& e) {
+  int res = MSG_process_sleep(30);
+  if (res == MSG_HOST_FAILURE) {
     XBT_INFO("The host has died ... as expected.");
   }
   XBT_INFO("  TX done");
     XBT_INFO("The host has died ... as expected.");
   }
   XBT_INFO("  TX done");