Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simply say fun_ptr(...) instead of (*fun_ptr)(...).
[simgrid.git] / src / gras / Msg / gras_msg_exchange.c
index c8dc08d..127ce0f 100644 (file)
@@ -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);
@@ -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);
   }