From 62674b2d4ef829283d1603eeeb0fcf1a20af8fec Mon Sep 17 00:00:00 2001 From: Samuel Lepetit Date: Wed, 16 May 2012 13:47:13 +0200 Subject: [PATCH] Change the way the process killing is handled, using the flag from the base context and not a specific flag on smx_context_java. It lets us now use a "process_kill" naturally :). --- src/jmsg_process.c | 22 +++++++++++++++------- src/smx_context_java.c | 5 ++--- src/smx_context_java.h | 1 - 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/jmsg_process.c b/src/jmsg_process.c index 83dcfbdf6d..9b3bb96d55 100644 --- a/src/jmsg_process.c +++ b/src/jmsg_process.c @@ -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; - - 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 @@ -280,7 +285,13 @@ Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess, 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()); } @@ -296,9 +307,6 @@ Java_org_simgrid_msg_Process_kill(JNIEnv * env, 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); } diff --git a/src/smx_context_java.c b/src/smx_context_java.c index fd385bb004..8065420e00 100644 --- a/src/smx_context_java.c +++ b/src/smx_context_java.c @@ -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->killed = 0; 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 */ - 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"); diff --git a/src/smx_context_java.h b/src/smx_context_java.h index d0578f00dc..4142bf120c 100644 --- a/src/smx_context_java.h +++ b/src/smx_context_java.h @@ -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 */ - int killed; } s_smx_ctx_java_t, *smx_ctx_java_t; void SIMIX_ctx_java_factory_init(smx_context_factory_t *factory); -- 2.20.1