Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid to throw an exception, and catch it just below.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Mon, 13 Feb 2012 09:37:32 +0000 (10:37 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Mon, 13 Feb 2012 09:53:07 +0000 (10:53 +0100)
Define SMX_EXCEPTION and SMX_THROW to hold the gory details.

Saves a couple of setjmp/longjmp.

src/simix/smx_host.c
src/simix/smx_io.c
src/simix/smx_network.c
src/simix/smx_private.h
src/simix/smx_process.c
src/simix/smx_synchro.c

index e87041b..01a4de8 100644 (file)
@@ -331,7 +331,7 @@ void SIMIX_host_execution_resume(smx_action_t action)
 
 void SIMIX_execution_finish(smx_action_t action)
 {
 
 void SIMIX_execution_finish(smx_action_t action)
 {
-  volatile xbt_fifo_item_t item;
+  xbt_fifo_item_t item;
   smx_simcall_t simcall;
 
   xbt_fifo_foreach(action->simcalls, item, simcall, smx_simcall_t) {
   smx_simcall_t simcall;
 
   xbt_fifo_foreach(action->simcalls, item, simcall, smx_simcall_t) {
@@ -345,23 +345,13 @@ void SIMIX_execution_finish(smx_action_t action)
 
       case SIMIX_FAILED:
         XBT_DEBUG("SIMIX_execution_finished: host '%s' failed", simcall->issuer->smx_host->name);
 
       case SIMIX_FAILED:
         XBT_DEBUG("SIMIX_execution_finished: host '%s' failed", simcall->issuer->smx_host->name);
-        TRY {
-          THROWF(host_error, 0, "Host failed");
-        }
-       CATCH(simcall->issuer->running_ctx->exception) {
-         simcall->issuer->doexception = 1;
-       }
-      break;
+        SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
+        break;
 
       case SIMIX_CANCELED:
         XBT_DEBUG("SIMIX_execution_finished: execution canceled");
 
       case SIMIX_CANCELED:
         XBT_DEBUG("SIMIX_execution_finished: execution canceled");
-        TRY {
-          THROWF(cancel_error, 0, "Canceled");
-        }
-       CATCH(simcall->issuer->running_ctx->exception) {
-         simcall->issuer->doexception = 1;
-        }
-       break;
+        SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
+        break;
 
       default:
         xbt_die("Internal error in SIMIX_execution_finish: unexpected action state %d",
 
       default:
         xbt_die("Internal error in SIMIX_execution_finish: unexpected action state %d",
index 031577d..a19b309 100644 (file)
@@ -247,7 +247,7 @@ void SIMIX_io_destroy(smx_action_t action)
 
 void SIMIX_io_finish(smx_action_t action)
 {
 
 void SIMIX_io_finish(smx_action_t action)
 {
-  volatile xbt_fifo_item_t item;
+  xbt_fifo_item_t item;
   smx_simcall_t simcall;
 
   xbt_fifo_foreach(action->simcalls, item, simcall, smx_simcall_t) {
   smx_simcall_t simcall;
 
   xbt_fifo_foreach(action->simcalls, item, simcall, smx_simcall_t) {
@@ -259,22 +259,12 @@ void SIMIX_io_finish(smx_action_t action)
         break;
 
       case SIMIX_FAILED:
         break;
 
       case SIMIX_FAILED:
-        TRY {
-          THROWF(io_error, 0, "IO failed");
-        }
-       CATCH(simcall->issuer->running_ctx->exception) {
-         simcall->issuer->doexception = 1;
-       }
-      break;
+        SMX_EXCEPTION(simcall->issuer, io_error, 0, "IO failed");
+        break;
 
       case SIMIX_CANCELED:
 
       case SIMIX_CANCELED:
-        TRY {
-          THROWF(cancel_error, 0, "Canceled");
-        }
-       CATCH(simcall->issuer->running_ctx->exception) {
-         simcall->issuer->doexception = 1;
-        }
-       break;
+        SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
+        break;
 
       default:
         xbt_die("Internal error in SIMIX_io_finish: unexpected action state %d",
 
       default:
         xbt_die("Internal error in SIMIX_io_finish: unexpected action state %d",
index 6c52ac7..74cefad 100644 (file)
@@ -569,7 +569,7 @@ XBT_INLINE void SIMIX_comm_start(smx_action_t action)
  */
 void SIMIX_comm_finish(smx_action_t action)
 {
  */
 void SIMIX_comm_finish(smx_action_t action)
 {
-  volatile unsigned int destroy_count = 0;
+  unsigned int destroy_count = 0;
   smx_simcall_t simcall;
 
   while ((simcall = xbt_fifo_shift(action->simcalls))) {
   smx_simcall_t simcall;
 
   while ((simcall = xbt_fifo_shift(action->simcalls))) {
@@ -599,80 +599,52 @@ void SIMIX_comm_finish(smx_action_t action)
         break;
 
       case SIMIX_SRC_TIMEOUT:
         break;
 
       case SIMIX_SRC_TIMEOUT:
-        TRY {
-          THROWF(timeout_error, 0, "Communication timeouted because of sender");
-        }
-       CATCH(simcall->issuer->running_ctx->exception) {
-          simcall->issuer->doexception = 1;
-        }
+        SMX_EXCEPTION(simcall->issuer, timeout_error, 0,
+                  "Communication timeouted because of sender");
         break;
 
       case SIMIX_DST_TIMEOUT:
         break;
 
       case SIMIX_DST_TIMEOUT:
-        TRY {
-          THROWF(timeout_error, 0, "Communication timeouted because of receiver");
-        }
-       CATCH(simcall->issuer->running_ctx->exception) {
-          simcall->issuer->doexception = 1;
-        }
+        SMX_EXCEPTION(simcall->issuer, timeout_error, 0,
+                  "Communication timeouted because of receiver");
         break;
 
       case SIMIX_SRC_HOST_FAILURE:
         break;
 
       case SIMIX_SRC_HOST_FAILURE:
-        TRY {
-          if (simcall->issuer == action->comm.src_proc)
-            THROWF(host_error, 0, "Host failed");
-          else
-            THROWF(network_error, 0, "Remote peer failed");
-        }
-       CATCH(simcall->issuer->running_ctx->exception) {
-          simcall->issuer->doexception = 1;
-        }
+        if (simcall->issuer == action->comm.src_proc)
+          SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
+        else
+          SMX_EXCEPTION(simcall->issuer, network_error, 0, "Remote peer failed");
         break;
 
       case SIMIX_DST_HOST_FAILURE:
         break;
 
       case SIMIX_DST_HOST_FAILURE:
-        TRY {
-          if (simcall->issuer == action->comm.dst_proc)
-            THROWF(host_error, 0, "Host failed");
-          else
-            THROWF(network_error, 0, "Remote peer failed");
-        }
-       CATCH(simcall->issuer->running_ctx->exception) {
-          simcall->issuer->doexception = 1;
-        }
+        if (simcall->issuer == action->comm.dst_proc)
+          SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
+        else
+          SMX_EXCEPTION(simcall->issuer, network_error, 0, "Remote peer failed");
         break;
 
       case SIMIX_LINK_FAILURE:
         break;
 
       case SIMIX_LINK_FAILURE:
-        TRY {
-          XBT_DEBUG("Link failure in action %p between '%s' and '%s': posting an exception to the issuer: %s (%p) detached:%d",
-              action,
-              action->comm.src_proc ? action->comm.src_proc->smx_host->name : NULL,
-              action->comm.dst_proc ? action->comm.dst_proc->smx_host->name : NULL,
-              simcall->issuer->name, simcall->issuer, action->comm.detached);
-          if (action->comm.src_proc == simcall->issuer) {
-            XBT_DEBUG("I'm source");
-          } else if (action->comm.dst_proc == simcall->issuer) {
-            XBT_DEBUG("I'm dest");
-          } else {
-            XBT_DEBUG("I'm neither source nor dest");
-          }
-          THROWF(network_error, 0, "Link failure");
-        }
-       CATCH(simcall->issuer->running_ctx->exception) {
-          simcall->issuer->doexception = 1;
+        XBT_DEBUG("Link failure in action %p between '%s' and '%s': posting an exception to the issuer: %s (%p) detached:%d",
+            action,
+            action->comm.src_proc ? action->comm.src_proc->smx_host->name : NULL,
+            action->comm.dst_proc ? action->comm.dst_proc->smx_host->name : NULL,
+            simcall->issuer->name, simcall->issuer, action->comm.detached);
+        if (action->comm.src_proc == simcall->issuer) {
+          XBT_DEBUG("I'm source");
+        } else if (action->comm.dst_proc == simcall->issuer) {
+          XBT_DEBUG("I'm dest");
+        } else {
+          XBT_DEBUG("I'm neither source nor dest");
         }
         }
+        SMX_EXCEPTION(simcall->issuer, network_error, 0, "Link failure");
         break;
 
       case SIMIX_CANCELED:
         break;
 
       case SIMIX_CANCELED:
-        TRY {
-          if (simcall->issuer == action->comm.dst_proc) {
-            THROWF(cancel_error, 0, "Communication canceled by the sender");
-          }
-          else {
-            THROWF(cancel_error, 0, "Communication canceled by the receiver");
-          }
-        }
-        CATCH(simcall->issuer->running_ctx->exception) {
-          simcall->issuer->doexception = 1;
-        }
+        if (simcall->issuer == action->comm.dst_proc)
+          SMX_EXCEPTION(simcall->issuer, cancel_error, 0,
+                    "Communication canceled by the sender");
+        else
+          SMX_EXCEPTION(simcall->issuer, cancel_error, 0,
+                    "Communication canceled by the receiver");
         break;
 
       default:
         break;
 
       default:
index 9c25e48..5571160 100644 (file)
@@ -46,6 +46,17 @@ typedef struct s_smx_global {
 extern smx_global_t simix_global;
 extern unsigned long simix_process_maxpid;
 
 extern smx_global_t simix_global;
 extern unsigned long simix_process_maxpid;
 
+/******************************** Exceptions *********************************/
+
+#define SMX_EXCEPTION(issuer, c, v, m)                                  \
+  if (1) {                                                              \
+    smx_process_t _smx_throw_issuer = (issuer);                         \
+    THROW_PREPARE(_smx_throw_issuer->running_ctx, (c), (v), xbt_strdup(m)); \
+    _smx_throw_issuer->doexception = 1;                                 \
+  } else ((void)0)
+
+#define SMX_THROW() RETHROW
+
 /*********************************** Time ************************************/
 
 /** @brief Timer datatype */
 /*********************************** Time ************************************/
 
 /** @brief Timer datatype */
index a6ed91e..048f5c3 100644 (file)
@@ -611,7 +611,7 @@ void SIMIX_process_yield(smx_process_t self)
   if (self->doexception) {
     XBT_DEBUG("Wait, maestro left me an exception");
     self->doexception = 0;
   if (self->doexception) {
     XBT_DEBUG("Wait, maestro left me an exception");
     self->doexception = 0;
-    RETHROW;
+    SMX_THROW();
   }
   
   if (self->new_host) {
   }
   
   if (self->new_host) {
index e85bfe3..d09b416 100644 (file)
@@ -96,21 +96,11 @@ static void SIMIX_synchro_finish(smx_action_t action)
   switch (action->state) {
 
     case SIMIX_SRC_TIMEOUT:
   switch (action->state) {
 
     case SIMIX_SRC_TIMEOUT:
-      TRY {
-        THROWF(timeout_error, 0, "Synchro's wait timeout");
-      }
-      CATCH(simcall->issuer->running_ctx->exception) {
-        simcall->issuer->doexception = 1;
-      }
+      SMX_EXCEPTION(simcall->issuer, timeout_error, 0, "Synchro's wait timeout");
       break;
 
     case SIMIX_FAILED:
       break;
 
     case SIMIX_FAILED:
-      TRY {
-        THROWF(host_error, 0, "Host failed");
-      }
-      CATCH(simcall->issuer->running_ctx->exception) {
-        simcall->issuer->doexception = 1;
-      }
+      SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
       break;
 
     default:
       break;
 
     default: