Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
xbt_cond_timedwait: catch C++ timeouts; convert into a C-complient return
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 27 Nov 2017 23:23:03 +0000 (00:23 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 27 Nov 2017 23:23:08 +0000 (00:23 +0100)
(fix #240)

include/xbt/synchro.h
src/simix/smx_private.hpp
src/xbt/xbt_os_synchro.cpp

index ba772f7..e5f7d06 100644 (file)
@@ -58,9 +58,9 @@ XBT_PUBLIC(xbt_cond_t) xbt_cond_init(void);
 
 /** @brief Blocks onto the given condition variable */
 XBT_PUBLIC(void) xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex);
-/** @brief Blocks onto the given condition variable, but only for the given amount of time. a timeout exception is
- *   raised if it was impossible to acquire it in the given time frame */
-XBT_PUBLIC(void) xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay);
+/** @brief Blocks onto the given condition variable, but only for the given amount of time.
+ *  @return 0 on success, 1 on timeout */
+XBT_PUBLIC(int) xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay);
 /** @brief Signals the given mutex variable */
 XBT_PUBLIC(void) xbt_cond_signal(xbt_cond_t cond);
 /** @brief Broadcasts the given mutex variable */
index a14ab8b..1a2ba34 100644 (file)
@@ -66,10 +66,10 @@ XBT_PUBLIC_DATA(std::unique_ptr<simgrid::simix::Global>) simix_global;
 XBT_PUBLIC(void) SIMIX_clean();
 
 /******************************** Exceptions *********************************/
-/** @brief Ask to the provided simix process to raise the provided exception */
+/** @brief Ask to the provided ActorImpl to raise the provided exception */
 #define SMX_EXCEPTION(issuer, cat, val, msg)                                                                           \
   if (1) {                                                                                                             \
-    smx_actor_t _smx_throw_issuer = (issuer); /* evaluate only once */                                                 \
+    simgrid::simix::ActorImpl* _smx_throw_issuer = (issuer); /* evaluate only once */                                  \
     xbt_ex e(XBT_THROW_POINT, msg);                                                                                    \
     e.category                   = cat;                                                                                \
     e.value                      = val;                                                                                \
index 748faa2..8973885 100644 (file)
@@ -6,7 +6,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "xbt/ex.h"
+#include "xbt/ex.hpp"
 #include "xbt/synchro.h"
 
 #include "simgrid/simix.h" /* used implementation */
@@ -50,9 +50,18 @@ void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex)
   simcall_cond_wait((smx_cond_t)cond, (smx_mutex_t)mutex);
 }
 
-void xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay)
+int xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay)
 {
-  simcall_cond_wait_timeout((smx_cond_t)cond, (smx_mutex_t)mutex, delay);
+  try {
+    simcall_cond_wait_timeout((smx_cond_t)cond, (smx_mutex_t)mutex, delay);
+  } catch (xbt_ex& e) {
+    if (e.category == timeout_error) {
+      return 1;
+    } else {
+      throw e; // unknown exception
+    }
+  }
+  return 0;
 }
 
 void xbt_cond_signal(xbt_cond_t cond)