env->ExceptionClear();
XBT_ATTRIB_UNUSED jint error = __java_vm->DetachCurrentThread();
xbt_assert(error == JNI_OK, "Cannot detach failing thread");
- simgrid::kernel::context::throw_stoprequest();
+ simgrid::kernel::context::StopRequest::do_throw();
}
}
{
double time = ((double)jmillis) / 1000 + ((double)jnanos) / 1000000000;
msg_error_t rv;
- if (not simgrid::kernel::context::try_n_catch_stoprequest([&rv, &time]() { rv = MSG_process_sleep(time); })) {
+ if (not simgrid::kernel::context::StopRequest::try_n_catch([&rv, &time]() { rv = MSG_process_sleep(time); })) {
rv = MSG_HOST_FAILURE;
}
if (rv != MSG_OK) {
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess, jdouble jseconds)
{
msg_error_t rv;
- if (not simgrid::kernel::context::try_n_catch_stoprequest(
+ if (not simgrid::kernel::context::StopRequest::try_n_catch(
[&rv, &jseconds]() { rv = MSG_process_sleep((double)jseconds); })) {
jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
}
jxbt_throw_notbound(env, "process", jprocess);
return;
}
- if (not simgrid::kernel::context::try_n_catch_stoprequest([&process]() { MSG_process_kill(process); })) {
+ if (not simgrid::kernel::context::StopRequest::try_n_catch([&process]() { MSG_process_kill(process); })) {
jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
}
}
return;
}
msg_error_t rv;
- if (not simgrid::kernel::context::try_n_catch_stoprequest([&rv, &task]() { rv = MSG_task_execute(task); })) {
+ if (not simgrid::kernel::context::StopRequest::try_n_catch([&rv, &task]() { rv = MSG_task_execute(task); })) {
jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
}
const char *alias = env->GetStringUTFChars(jalias, 0);
msg_error_t rv;
- if (not simgrid::kernel::context::try_n_catch_stoprequest([&rv, &task, &alias, &jtimeout]() {
+ if (not simgrid::kernel::context::StopRequest::try_n_catch([&rv, &task, &alias, &jtimeout]() {
rv = MSG_task_receive_ext(&task, alias, (double)jtimeout, /*host*/ nullptr);
})) {
jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
StopRequest::~StopRequest() = default;
-void throw_stoprequest()
+void StopRequest::do_throw()
{
throw StopRequest();
}
-bool try_n_catch_stoprequest(std::function<void(void)> try_block)
+bool StopRequest::try_n_catch(std::function<void(void)> try_block)
{
bool res;
try {
~StopRequest();
const char* what() const noexcept { return msg_.c_str(); }
+ static void do_throw();
+ static bool try_n_catch(std::function<void(void)> try_block);
+
private:
std::string msg_ = std::string("Actor killed.");
};
-XBT_PUBLIC void throw_stoprequest();
-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)();