Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define helper functions to use Context::StopRequest outside of libsimgrid.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 23 Jan 2019 22:17:48 +0000 (23:17 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 23 Jan 2019 22:20:21 +0000 (23:20 +0100)
Rationale: exceptions sometimes fail to pass correctly between shared
libraries, specially on FreeBSD or OS X.

src/kernel/context/Context.cpp
src/kernel/context/Context.hpp

index 06e5402..09131d8 100644 (file)
@@ -101,6 +101,24 @@ void Context::stop()
 
 AttachContext::~AttachContext() = default;
 
+void throw_stoprequest()
+{
+  throw Context::StopRequest();
+}
+
+bool try_n_catch_stoprequest(std::function<void(void)> try_block, std::function<void(void)> catch_block)
+{
+  bool res;
+  try {
+    try_block();
+    res = true;
+  } catch (Context::StopRequest const&) {
+    XBT_DEBUG("Caught a StopRequest");
+    catch_block();
+    res = false;
+  }
+  return res;
+}
 }}}
 
 /** @brief Executes all the processes to run (in parallel if possible). */
index 6543800..f60a6cd 100644 (file)
@@ -10,6 +10,7 @@
 #include "src/kernel/activity/ActivityImpl.hpp"
 
 #include <csignal>
+#include <functional>
 
 /* Process creation/destruction callbacks */
 typedef void (*void_pfn_smxprocess_t)(smx_actor_t);
@@ -106,6 +107,9 @@ public:
   virtual void attach_stop() = 0;
 };
 
+XBT_PUBLIC void throw_stoprequest();
+XBT_PUBLIC bool try_n_catch_stoprequest(std::function<void(void)> try_block, std::function<void(void)> catch_block);
+
 /* This allows Java to hijack the context factory (Java induces factories of factory :) */
 typedef ContextFactory* (*ContextFactoryInitializer)();
 XBT_PUBLIC_DATA ContextFactoryInitializer factory_initializer;