From: Arnaud Giersch Date: Mon, 13 Feb 2012 09:37:32 +0000 (+0100) Subject: Avoid to throw an exception, and catch it just below. X-Git-Tag: exp_20120216~16 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/28fd49f9900e7a8424f38cafd21682f8c732ed42?ds=sidebyside Avoid to throw an exception, and catch it just below. Define SMX_EXCEPTION and SMX_THROW to hold the gory details. Saves a couple of setjmp/longjmp. --- diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index e87041bc51..01a4de8831 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -331,7 +331,7 @@ void SIMIX_host_execution_resume(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) { @@ -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); - 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"); - 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", diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 031577da60..a19b3093bf 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -247,7 +247,7 @@ void SIMIX_io_destroy(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) { @@ -259,22 +259,12 @@ void SIMIX_io_finish(smx_action_t action) 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: - 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", diff --git a/src/simix/smx_network.c b/src/simix/smx_network.c index 6c52ac7a86..74cefadfa5 100644 --- a/src/simix/smx_network.c +++ b/src/simix/smx_network.c @@ -569,7 +569,7 @@ XBT_INLINE void SIMIX_comm_start(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))) { @@ -599,80 +599,52 @@ void SIMIX_comm_finish(smx_action_t action) 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: - 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: - 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: - 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: - 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: - 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: diff --git a/src/simix/smx_private.h b/src/simix/smx_private.h index 9c25e4838e..5571160f6b 100644 --- a/src/simix/smx_private.h +++ b/src/simix/smx_private.h @@ -46,6 +46,17 @@ typedef struct s_smx_global { 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 */ diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index a6ed91e64d..048f5c3ec7 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -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; - RETHROW; + SMX_THROW(); } if (self->new_host) { diff --git a/src/simix/smx_synchro.c b/src/simix/smx_synchro.c index e85bfe3a4c..d09b4163f9 100644 --- a/src/simix/smx_synchro.c +++ b/src/simix/smx_synchro.c @@ -96,21 +96,11 @@ static void SIMIX_synchro_finish(smx_action_t action) 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: - 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: