Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add support for CancelException
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 16 Feb 2019 19:08:50 +0000 (20:08 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 16 Feb 2019 19:08:50 +0000 (20:08 +0100)
include/simgrid/Exception.hpp
src/msg/msg_gos.cpp
src/simix/smx_host.cpp
src/simix/smx_io.cpp
src/simix/smx_network.cpp

index db16dd9..b414b15 100644 (file)
@@ -146,6 +146,12 @@ public:
 
 /** Exception raised when something got canceled before completion */
 class CancelException : public xbt_ex {
+public:
+  CancelException(simgrid::xbt::ThrowPoint throwpoint, std::string message)
+      : xbt_ex(std::move(throwpoint), std::move(message))
+  {
+    category = cancel_error;
+  }
 };
 
 } // namespace simgrid
index ed29814..8f3b098 100644 (file)
@@ -92,11 +92,8 @@ msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeo
     status = MSG_HOST_FAILURE;
   } catch (simgrid::TimeoutError& e) {
     status = MSG_TIMEOUT;
-  } catch (xbt_ex& e) {
-    if (e.category == cancel_error)
-      status = MSG_TASK_CANCELED;
-    else
-      throw;
+  } catch (simgrid::CancelException& e) {
+    status = MSG_TASK_CANCELED;
   }
 
   /* action ended, set comm and compute = nullptr, the actions is already destroyed in the main function */
@@ -259,17 +256,13 @@ msg_error_t MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, d
     ret = MSG_HOST_FAILURE;
   } catch (simgrid::TimeoutError& e) {
     ret = MSG_TIMEOUT;
+  } catch (simgrid::CancelException& e) {
+    ret = MSG_HOST_FAILURE;
   } catch (xbt_ex& e) {
-    switch (e.category) {
-    case cancel_error:
-      ret = MSG_HOST_FAILURE;
-      break;
-    case network_error:
+    if (e.category == network_error)
       ret = MSG_TRANSFER_FAILURE;
-      break;
-    default:
+    else
       throw;
-    }
   }
 
   if (ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) {
@@ -752,18 +745,13 @@ msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, doubl
     simcall_comm_wait(comm, timeout);
   } catch (simgrid::TimeoutError& e) {
     ret = MSG_TIMEOUT;
-  }
-  catch (xbt_ex& e) {
-    switch (e.category) {
-    case cancel_error:
-      ret = MSG_HOST_FAILURE;
-      break;
-    case network_error:
+  } catch (simgrid::CancelException& e) {
+    ret = MSG_HOST_FAILURE;
+  } catch (xbt_ex& e) {
+    if (e.category == network_error)
       ret = MSG_TRANSFER_FAILURE;
-      break;
-    default:
+    else
       throw;
-    }
 
     /* If the send failed, it is not used anymore */
     t_simdata->setNotUsed();
index b7ce26d..8f17148 100644 (file)
@@ -113,7 +113,8 @@ void SIMIX_execution_finish(smx_activity_t synchro)
 
       case SIMIX_CANCELED:
         XBT_DEBUG("SIMIX_execution_finished: execution canceled");
-        SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
+        simcall->issuer->exception =
+            std::make_exception_ptr(simgrid::CancelException(XBT_THROW_POINT, "Execution Canceled"));
         break;
 
       case SIMIX_TIMEOUT:
index bb18ed0..b82e48d 100644 (file)
@@ -47,7 +47,7 @@ void SIMIX_io_finish(smx_activity_t synchro)
         SMX_EXCEPTION(simcall->issuer, io_error, 0, "IO failed");
         break;
       case SIMIX_CANCELED:
-        SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
+        simcall->issuer->exception = std::make_exception_ptr(simgrid::CancelException(XBT_THROW_POINT, "I/O Canceled"));
         break;
       default:
         xbt_die("Internal error in SIMIX_io_finish: unexpected synchro state %d", static_cast<int>(synchro->state_));
index b855c9f..7916873 100644 (file)
@@ -446,9 +446,11 @@ void SIMIX_comm_finish(smx_activity_t synchro)
 
         case SIMIX_CANCELED:
           if (simcall->issuer == comm->dst_actor_)
-            SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Communication canceled by the sender");
+            simcall->issuer->exception = std::make_exception_ptr(
+                simgrid::CancelException(XBT_THROW_POINT, "Communication canceled by the sender"));
           else
-            SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Communication canceled by the receiver");
+            simcall->issuer->exception = std::make_exception_ptr(
+                simgrid::CancelException(XBT_THROW_POINT, "Communication canceled by the receiver"));
           break;
 
         default:
@@ -483,13 +485,9 @@ void SIMIX_comm_finish(smx_activity_t synchro)
       } catch (simgrid::NetworkFailureException& e) {
         e.value                    = rank;
         simcall->issuer->exception = std::make_exception_ptr(e);
-      } catch (xbt_ex& e) {
-        if (e.category == cancel_error) {
-          e.value                    = rank;
-          simcall->issuer->exception = std::make_exception_ptr(e);
-        } else {
-          xbt_die("Unexpected xbt_ex(%s). Please enhance this code", xbt_ex_catname(e.category));
-        }
+      } catch (simgrid::CancelException& e) {
+        e.value                    = rank;
+        simcall->issuer->exception = std::make_exception_ptr(e);
       }
     }