X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/82b9a1db9168e46fb62edc6fa0b3f6fb09b2a7fd..c5c3f1bfece15c7b3a17a4f41925eae5cd629507:/src/jmsg_process.c diff --git a/src/jmsg_process.c b/src/jmsg_process.c index b7d7a3bf23..ecb1890a4b 100644 --- a/src/jmsg_process.c +++ b/src/jmsg_process.c @@ -14,13 +14,6 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); -static jfieldID jprocess_field_Process_bind; -static jfieldID jprocess_field_Process_name; -static jfieldID jprocess_field_Process_host; -static jfieldID jprocess_field_Process_id; -static jfieldID jprocess_field_Process_pid; -static jfieldID jprocess_field_Process_ppid; - jobject native_to_java_process(m_process_t process) { return ((smx_ctx_java_t)MSG_process_get_smx_ctx(process))->jprocess; @@ -84,7 +77,7 @@ Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls) { jprocess_field_Process_pid = jxbt_get_jfield(env, jprocess_class_Process, "pid", "I"); jprocess_field_Process_ppid = jxbt_get_jfield(env, jprocess_class_Process, "ppid", "I"); jprocess_field_Process_host = jxbt_get_jfield(env, jprocess_class_Process, "host", "Lorg/simgrid/msg/Host;"); - + jprocess_field_Process_killTime = jxbt_get_jfield(env, jprocess_class_Process, "killTime", "D"); if (!jprocess_class_Process || !jprocess_field_Process_id || !jprocess_field_Process_name || !jprocess_field_Process_pid || !jprocess_field_Process_ppid || !jprocess_field_Process_host) { jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug.")); @@ -137,15 +130,16 @@ Java_org_simgrid_msg_Process_create(JNIEnv * env, name = (*env)->GetStringUTFChars(env, jname, 0); name = xbt_strdup(name); + /* Retrieve the kill time from the process */ + jdouble jkill = (*env)->GetDoubleField(env, jprocess, jprocess_field_Process_killTime); /* Actually build the MSG process */ process = MSG_process_create_with_environment(name, (xbt_main_func_t) jprocess, - /*data*/ NULL, + /*data*/ jprocess, host, - /* kill_time */-1, /*argc, argv, properties*/ 0,NULL,NULL); - + MSG_process_set_kill_time(process, (double)jkill); MSG_process_set_data(process,&process); /* bind the java process instance to the native process */ jprocess_bind(jprocess, process, env); @@ -265,24 +259,31 @@ 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, - bprintf("unexpected error , please report this bug")); + MSG_error_t rv; + TRY { + rv = MSG_process_sleep(time); + } + CATCH_ANONYMOUS { + return; + } + if (rv != MSG_OK) { + jmsg_throw_status(env,rv); + } } JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess, jdouble jseconds) { - m_process_t process = jprocess_to_native_process(jprocess, env); - - if (!process) { - jxbt_throw_notbound(env, "process", jprocess); - return; + MSG_error_t rv; + TRY { + rv = MSG_process_sleep((double)jseconds); + } + CATCH_ANONYMOUS { + return; } - MSG_error_t rv = MSG_process_sleep((double)jseconds); if (rv != MSG_OK) { -// smx_ctx_java_stop(smx_ctx_java_self()); + XBT_INFO("Status NOK"); + jmsg_throw_status(env,rv); } } @@ -296,9 +297,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); }