Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove useless 2nd parameter "catch_block" for try_n_catch_stoprequest().
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 23 Jan 2019 22:49:32 +0000 (23:49 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 24 Jan 2019 07:48:04 +0000 (08:48 +0100)
src/bindings/java/jmsg_process.cpp
src/bindings/java/jmsg_task.cpp
src/kernel/context/Context.cpp
src/kernel/context/Context.hpp

index 5ea0d3e..3e2abe0 100644 (file)
@@ -225,8 +225,9 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cl
  {
   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");
 
@@ -237,10 +238,10 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cl
 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) {
@@ -257,9 +258,9 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill(JNIEnv * env, jobject j
     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)
index 47182e2..31b504d 100644 (file)
@@ -127,9 +127,9 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_execute(JNIEnv * env, jobject j
     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;
@@ -286,11 +286,11 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_receive(JNIEnv* env, jclass
 
   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;
index 09131d8..359ddf6 100644 (file)
@@ -106,7 +106,7 @@ void throw_stoprequest()
   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 {
@@ -114,7 +114,6 @@ bool try_n_catch_stoprequest(std::function<void(void)> try_block, std::function<
     res = true;
   } catch (Context::StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
-    catch_block();
     res = false;
   }
   return res;
index f60a6cd..b77601c 100644 (file)
@@ -108,7 +108,7 @@ public:
 };
 
 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)();