Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change helper functions to static methods of StopRequest.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 24 Jan 2019 11:04:01 +0000 (12:04 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 25 Jan 2019 11:31:34 +0000 (12:31 +0100)
src/bindings/java/jmsg.cpp
src/bindings/java/jmsg_process.cpp
src/bindings/java/jmsg_task.cpp
src/kernel/context/Context.cpp
src/kernel/context/Context.hpp

index 528510a..4b81f4e 100644 (file)
@@ -270,7 +270,7 @@ static void run_jprocess(JNIEnv *env, jobject jprocess)
     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();
   }
 }
 
index 3e2abe0..fc495a5 100644 (file)
@@ -225,7 +225,7 @@ 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;
-  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) {
@@ -238,7 +238,7 @@ 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;
-  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");
   }
@@ -258,7 +258,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill(JNIEnv * env, jobject j
     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");
   }
 }
index 31b504d..b017a48 100644 (file)
@@ -127,7 +127,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_execute(JNIEnv * env, jobject j
     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");
   }
 
@@ -286,7 +286,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_receive(JNIEnv* env, jclass
 
   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");
index fb8aacb..e095919 100644 (file)
@@ -103,12 +103,12 @@ AttachContext::~AttachContext() = default;
 
 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 {
index 06bd27a..1cf7104 100644 (file)
@@ -104,11 +104,12 @@ public:
   ~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)();