{
double time = ((double)jmillis) / 1000 + ((double)jnanos) / 1000000000;
msg_error_t rv;
- simgrid::kernel::context::try_n_catch_stoprequest([&rv, &time]() { rv = MSG_process_sleep(time); },
- [&rv]() { rv = MSG_HOST_FAILURE; });
+ if (not simgrid::kernel::context::try_n_catch_stoprequest([&rv, &time]() { rv = MSG_process_sleep(time); })) {
+ rv = MSG_HOST_FAILURE;
+ }
if (rv != MSG_OK) {
XBT_DEBUG("Something during the MSG_process_sleep invocation was wrong, trigger a HostFailureException");
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess, jdouble jseconds)
{
msg_error_t rv;
- simgrid::kernel::context::try_n_catch_stoprequest(
- [&rv, &jseconds]() { rv = MSG_process_sleep((double)jseconds); },
- [&env]() { jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed"); });
-
+ if (not simgrid::kernel::context::try_n_catch_stoprequest(
+ [&rv, &jseconds]() { rv = MSG_process_sleep((double)jseconds); })) {
+ jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
+ }
if (env->ExceptionOccurred())
return;
if (rv != MSG_OK) {
jxbt_throw_notbound(env, "process", jprocess);
return;
}
- simgrid::kernel::context::try_n_catch_stoprequest(
- [&process]() { MSG_process_kill(process); },
- [&env]() { jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed"); });
+ if (not simgrid::kernel::context::try_n_catch_stoprequest([&process]() { MSG_process_kill(process); })) {
+ jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
+ }
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate(JNIEnv * env, jobject jprocess, jobject jhost)
return;
}
msg_error_t rv;
- simgrid::kernel::context::try_n_catch_stoprequest(
- [&rv, &task]() { rv = MSG_task_execute(task); },
- [&env] { jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed"); });
+ if (not simgrid::kernel::context::try_n_catch_stoprequest([&rv, &task]() { rv = MSG_task_execute(task); })) {
+ jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
+ }
if (env->ExceptionOccurred())
return;
const char *alias = env->GetStringUTFChars(jalias, 0);
msg_error_t rv;
- simgrid::kernel::context::try_n_catch_stoprequest(
- [&rv, &task, &alias, &jtimeout]() {
+ if (not simgrid::kernel::context::try_n_catch_stoprequest([&rv, &task, &alias, &jtimeout]() {
rv = MSG_task_receive_ext(&task, alias, (double)jtimeout, /*host*/ nullptr);
- },
- [&env]() { jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed"); });
+ })) {
+ jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
+ }
env->ReleaseStringUTFChars(jalias, alias);
if (env->ExceptionOccurred())
return nullptr;
throw Context::StopRequest();
}
-bool try_n_catch_stoprequest(std::function<void(void)> try_block, std::function<void(void)> catch_block)
+bool try_n_catch_stoprequest(std::function<void(void)> try_block)
{
bool res;
try {
res = true;
} catch (Context::StopRequest const&) {
XBT_DEBUG("Caught a StopRequest");
- catch_block();
res = false;
}
return res;
};
XBT_PUBLIC void throw_stoprequest();
-XBT_PUBLIC bool try_n_catch_stoprequest(std::function<void(void)> try_block, std::function<void(void)> catch_block);
+XBT_PUBLIC bool try_n_catch_stoprequest(std::function<void(void)> try_block);
/* This allows Java to hijack the context factory (Java induces factories of factory :) */
typedef ContextFactory* (*ContextFactoryInitializer)();