Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the way the process killing is handled, using the flag from the base context...
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Wed, 16 May 2012 11:47:13 +0000 (13:47 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Wed, 16 May 2012 11:47:13 +0000 (13:47 +0200)
specific flag on smx_context_java.

It lets us now use a "process_kill" naturally :).

src/jmsg_process.c
src/smx_context_java.c
src/smx_context_java.h

index 83dcfbd..9b3bb96 100644 (file)
@@ -265,9 +265,14 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep
        (JNIEnv *env, jclass cls, jlong jmillis, jint jnanos) {
 
        double time =  jmillis / 1000 + jnanos / 1000;
        (JNIEnv *env, jclass cls, jlong jmillis, jint jnanos) {
 
        double time =  jmillis / 1000 + jnanos / 1000;
-
-       MSG_error_t rv = MSG_process_sleep(time);
-  jxbt_check_res("MSG_process_sleep()", rv, MSG_OK,
+       MSG_error_t rv;
+       TRY {
+               rv = MSG_process_sleep(time);
+       }
+       CATCH_ANONYMOUS {
+               return;
+       }
+       jxbt_check_res("MSG_process_sleep()", rv, MSG_OK,
                  bprintf("unexpected error , please report this bug"));
 }
 JNIEXPORT void JNICALL
                  bprintf("unexpected error , please report this bug"));
 }
 JNIEXPORT void JNICALL
@@ -280,7 +285,13 @@ Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess,
     jxbt_throw_notbound(env, "process", jprocess);
     return;
   }
     jxbt_throw_notbound(env, "process", jprocess);
     return;
   }
-  MSG_error_t rv = MSG_process_sleep((double)jseconds);
+  MSG_error_t rv;
+  TRY {
+        rv = MSG_process_sleep((double)jseconds);
+  }
+  CATCH_ANONYMOUS {
+       return;
+  }
   if (rv != MSG_OK) {
 //     smx_ctx_java_stop(smx_ctx_java_self());
   }
   if (rv != MSG_OK) {
 //     smx_ctx_java_stop(smx_ctx_java_self());
   }
@@ -296,9 +307,6 @@ Java_org_simgrid_msg_Process_kill(JNIEnv * env,
     jxbt_throw_notbound(env, "process", jprocess);
     return;
   }
     jxbt_throw_notbound(env, "process", jprocess);
     return;
   }
-  /* Sets the "killed" flag to kill the process on the next unschedule */
-  smx_ctx_java_t context = (smx_ctx_java_t)MSG_process_get_smx_ctx(process);
-       context->killed = 1;
 
        MSG_process_kill(process);
 }
 
        MSG_process_kill(process);
 }
index fd385bb..8065420 100644 (file)
@@ -75,7 +75,6 @@ smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc,
     context->jprocess = (jobject) code;
     context->begin = xbt_os_sem_init(0);
     context->end = xbt_os_sem_init(0);
     context->jprocess = (jobject) code;
     context->begin = xbt_os_sem_init(0);
     context->end = xbt_os_sem_init(0);
-    context->killed = 0;
     context->thread = xbt_os_thread_create(NULL,smx_ctx_java_thread_run,context,NULL);
   }
   else {
     context->thread = xbt_os_thread_create(NULL,smx_ctx_java_thread_run,context,NULL);
   }
   else {
@@ -133,8 +132,8 @@ void smx_ctx_java_stop(smx_context_t context)
        xbt_assert(context == my_current_context,
      "The context to stop must be the current one");
   /* I am the current process and I am dying */
        xbt_assert(context == my_current_context,
      "The context to stop must be the current one");
   /* I am the current process and I am dying */
-  if (ctx_java->killed == 1) {
-       ctx_java->killed = 0;
+       if (context->iwannadie == -1) {
+       context->iwannadie = 0;
        JNIEnv *env = get_current_thread_env();
        jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", bprintf("Process killed :)"));
        THROWF(cancel_error, 0, "process cancelled");
        JNIEnv *env = get_current_thread_env();
        jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", bprintf("Process killed :)"));
        THROWF(cancel_error, 0, "process cancelled");
index d0578f0..4142bf1 100644 (file)
@@ -23,7 +23,6 @@ typedef struct s_smx_ctx_java {
   xbt_os_thread_t thread;
   xbt_os_sem_t begin;           /* this semaphore is used to schedule/yield the process  */
   xbt_os_sem_t end;             /* this semaphore is used to schedule/unschedule the process   */
   xbt_os_thread_t thread;
   xbt_os_sem_t begin;           /* this semaphore is used to schedule/yield the process  */
   xbt_os_sem_t end;             /* this semaphore is used to schedule/unschedule the process   */
-  int killed;
 } s_smx_ctx_java_t, *smx_ctx_java_t;
 
 void SIMIX_ctx_java_factory_init(smx_context_factory_t *factory);
 } s_smx_ctx_java_t, *smx_ctx_java_t;
 
 void SIMIX_ctx_java_factory_init(smx_context_factory_t *factory);