X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6ee7e9c2e455536ab817ae0136acfbb53822eecd..997eaf52ad0ae1eb34820b135c7ba884b2a17f3c:/src/gras/Msg/gras_msg_exchange.c diff --git a/src/gras/Msg/gras_msg_exchange.c b/src/gras/Msg/gras_msg_exchange.c index c8dc08d14d..66f6e64a26 100644 --- a/src/gras/Msg/gras_msg_exchange.c +++ b/src/gras/Msg/gras_msg_exchange.c @@ -46,7 +46,7 @@ gras_msg_wait_ext_(double timeout, (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); unsigned int cpt; - xbt_assert0(msg_got, "msg_got is an output parameter"); + xbt_assert(msg_got, "msg_got is an output parameter"); start = gras_os_time(); XBT_VERB("Waiting for message '%s' for %fs", @@ -122,7 +122,7 @@ gras_msg_wait_ext_(double timeout, now = gras_os_time(); if (now - start + 0.001 > timeout) { - THROW1(timeout_error, now - start + 0.001 - timeout, + THROWF(timeout_error, now - start + 0.001 - timeout, "Timeout while waiting for msg '%s'", msgt_want ? msgt_want->name : "(any)"); } @@ -152,11 +152,11 @@ gras_msg_wait_(double timeout, gras_msg_wait_ext_(timeout, msgt_want, NULL, NULL, NULL, &msg); if (msgt_want->ctn_type) { - xbt_assert1(payload, + xbt_assert(payload, "Message type '%s' convey a payload that you must accept", msgt_want->name); } else { - xbt_assert1(!payload, + xbt_assert(!payload, "No payload was declared for message type '%s' (don't expect one)", msgt_want->name); } @@ -209,7 +209,7 @@ void gras_msg_wait_or(double timeout, &gras_msg_wait_or_filter, (void *) msgt_want, &msg); if (msg.type->ctn_type) { - xbt_assert1(payload, + xbt_assert(payload, "Message type '%s' convey a payload you must accept", msg.type->name); } @@ -235,11 +235,11 @@ void gras_msg_send_(gras_socket_t sock, gras_msgtype_t msgtype, { if (msgtype->ctn_type) { - xbt_assert1(payload, + xbt_assert(payload, "Message type '%s' convey a payload you must provide", msgtype->name); } else { - xbt_assert1(!payload, + xbt_assert(!payload, "No payload was declared for message type '%s'", msgtype->name); } @@ -274,7 +274,7 @@ void gras_msg_handleall(double period) } CATCH(e) { if (e.category != timeout_error) - RETHROW0("Error while waiting for messages: %s"); + RETHROWF("Error while waiting for messages: %s"); xbt_ex_free(e); } /* Epsilon to avoid numerical stability issues were the waited interval is so small that the global clock cannot notice the increment */ @@ -290,13 +290,13 @@ void gras_msg_handleall(double period) * * @sa gras_msg_handleall(). */ -void gras_msg_handle(double timeOut) +void gras_msg_handle(volatile double timeOut) { double untiltimer; unsigned int cpt; - int volatile ran_ok; + volatile int ran_ok; s_gras_msg_t msg; @@ -306,7 +306,7 @@ void gras_msg_handle(double timeOut) gras_msg_cb_t cb; s_gras_msg_cb_ctx_t ctx; - int timerexpected, timeouted; + volatile int timerexpected, timeouted; xbt_ex_t e; XBT_VERB("Handling message within the next %.2fs", timeOut); @@ -326,7 +326,7 @@ void gras_msg_handle(double timeOut) /* get a message (from the queue or from the net) */ timeouted = 0; - if (xbt_dynar_length(pd->msg_queue)) { + if (!xbt_dynar_is_empty(pd->msg_queue)) { XBT_DEBUG("Get a message from the queue"); xbt_dynar_shift(pd->msg_queue, &msg); } else { @@ -352,19 +352,19 @@ void gras_msg_handle(double timeOut) /* we served a timer, we're done */ return; } else { - xbt_assert1(untiltimer > 0, "Negative timer (%f). I'm 'puzzeled'", + xbt_assert(untiltimer > 0, "Negative timer (%f). I'm 'puzzeled'", untiltimer); XBT_WARN ("No timer elapsed, in contrary to expectations (next in %f sec)", untiltimer); - THROW1(timeout_error, 0, + THROWF(timeout_error, 0, "No timer elapsed, in contrary to expectations (next in %f sec)", untiltimer); } } else { /* select timeouted, and no timer elapsed. Nothing to do */ - THROW1(timeout_error, 0, "No new message or timer (delay was %f)", + THROWF(timeout_error, 0, "No new message or timer (delay was %f)", timeOut); } @@ -398,16 +398,18 @@ void gras_msg_handle(double timeOut) ran_ok = 0; TRY { xbt_dynar_foreach(list->cbs, cpt, cb) { + volatile unsigned int cpt2 = cpt; if (!ran_ok) { XBT_DEBUG ("Use the callback #%d (@%p) for incomming msg '%s' (payload_size=%d)", cpt + 1, cb, msg.type->name, msg.payl_size); - if (!(*cb) (&ctx, msg.payl)) { + if (!cb(&ctx, msg.payl)) { /* cb handled the message */ free(msg.payl); ran_ok = 1; } } + cpt = cpt2; } } CATCH(e) { @@ -438,13 +440,13 @@ void gras_msg_handle(double timeOut) ctx.answer_due = 0; ran_ok = 1; } else { - RETHROW4 + RETHROWF ("Callback #%d (@%p) to message '%s' (payload size: %d) raised an exception: %s", cpt + 1, cb, msg.type->name, msg.payl_size); } } - xbt_assert1(!ctx.answer_due, + xbt_assert(!ctx.answer_due, "Bug in user code: RPC callback to message '%s' didn't call gras_msg_rpcreturn", msg.type->name); if (ctx.answer_due) @@ -453,7 +455,7 @@ void gras_msg_handle(double timeOut) "AND IN SIMGRID (process wasn't killed by an assert)", msg.type->name); if (!ran_ok) - THROW1(mismatch_error, 0, + THROWF(mismatch_error, 0, "Message '%s' refused by all registered callbacks (maybe your callback misses a 'return 0' at the end)", msg.type->name); /* FIXME: gras_datadesc_free not implemented => leaking the payload */ @@ -477,7 +479,7 @@ void gras_msg_handle(double timeOut) return; default: - THROW1(unknown_error, 0, + THROWF(unknown_error, 0, "Cannot handle messages of kind %d yet", msg.type->kind); }