From: Arnaud Giersch Date: Wed, 23 Jan 2019 22:17:48 +0000 (+0100) Subject: Define helper functions to use Context::StopRequest outside of libsimgrid. X-Git-Tag: v3_22~493 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0f48c2d922a965695be62f682811459b901f01ea?ds=sidebyside Define helper functions to use Context::StopRequest outside of libsimgrid. Rationale: exceptions sometimes fail to pass correctly between shared libraries, specially on FreeBSD or OS X. --- diff --git a/src/kernel/context/Context.cpp b/src/kernel/context/Context.cpp index 06e540232a..09131d8022 100644 --- a/src/kernel/context/Context.cpp +++ b/src/kernel/context/Context.cpp @@ -101,6 +101,24 @@ void Context::stop() AttachContext::~AttachContext() = default; +void throw_stoprequest() +{ + throw Context::StopRequest(); +} + +bool try_n_catch_stoprequest(std::function try_block, std::function 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). */ diff --git a/src/kernel/context/Context.hpp b/src/kernel/context/Context.hpp index 654380042d..f60a6cdc5b 100644 --- a/src/kernel/context/Context.hpp +++ b/src/kernel/context/Context.hpp @@ -10,6 +10,7 @@ #include "src/kernel/activity/ActivityImpl.hpp" #include +#include /* 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 try_block, std::function catch_block); + /* This allows Java to hijack the context factory (Java induces factories of factory :) */ typedef ContextFactory* (*ContextFactoryInitializer)(); XBT_PUBLIC_DATA ContextFactoryInitializer factory_initializer;