From 4fb1548b520dfebdd649916e63f588569aa599c9 Mon Sep 17 00:00:00 2001 From: Samuel Lepetit Date: Thu, 31 May 2012 10:18:25 +0200 Subject: [PATCH 1/1] Add a boolean field "finished" in Comm to prevent exceptions in Simix to happen --- org/simgrid/msg/Comm.java | 6 +++++- org/simgrid/msg/Process.java | 1 - src/jmsg_comm.c | 20 +++++++++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/org/simgrid/msg/Comm.java b/org/simgrid/msg/Comm.java index d3d979964c..423371db1a 100644 --- a/org/simgrid/msg/Comm.java +++ b/org/simgrid/msg/Comm.java @@ -15,7 +15,11 @@ public class Comm { /** * Indicates if the communication is a receiving communication */ - boolean receiving; + protected boolean receiving; + /** + * Indicates if the communication is finished + */ + protected boolean finished = false; /** * Represents the bind between the java comm and the * native C comm. You must never access it, since it is diff --git a/org/simgrid/msg/Process.java b/org/simgrid/msg/Process.java index abdd52ca4b..82e6c4fe16 100644 --- a/org/simgrid/msg/Process.java +++ b/org/simgrid/msg/Process.java @@ -224,7 +224,6 @@ public abstract class Process implements Runnable { /** * This method kill a process. - * @param process the process to be killed. * */ public native void kill(); diff --git a/src/jmsg_comm.c b/src/jmsg_comm.c index 48638c04c0..976cf7e10b 100644 --- a/src/jmsg_comm.c +++ b/src/jmsg_comm.c @@ -8,10 +8,11 @@ #include XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); -static jfieldID jtask_field_Comm_task; static jfieldID jcomm_field_Comm_bind; -static jfieldID jcomm_field_Comm_taskBind; +static jfieldID jcomm_field_Comm_finished; static jfieldID jcomm_field_Comm_receiving; +static jfieldID jtask_field_Comm_task; +static jfieldID jcomm_field_Comm_taskBind; void jcomm_bind_task(JNIEnv *env, jobject jcomm) { msg_comm_t comm = (msg_comm_t) (long) (*env)->GetLongField(env, jcomm, jcomm_field_Comm_bind); @@ -49,7 +50,8 @@ Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls) { jcomm_field_Comm_taskBind = jxbt_get_jfield(env, jfield_class_Comm, "taskBind", "J"); jcomm_field_Comm_receiving = jxbt_get_jfield(env, jfield_class_Comm, "receiving", "Z"); jtask_field_Comm_task = jxbt_get_jfield(env, jfield_class_Comm, "task", "Lorg/simgrid/msg/Task;"); - if (!jcomm_field_Comm_bind || !jcomm_field_Comm_taskBind || !jcomm_field_Comm_receiving || !jtask_field_Comm_task) { + jcomm_field_Comm_finished = jxbt_get_jfield(env, jfield_class_Comm, "finished", "Z"); + if (!jcomm_field_Comm_bind || !jcomm_field_Comm_taskBind || !jcomm_field_Comm_receiving || !jtask_field_Comm_task || !jcomm_field_Comm_finished) { jxbt_throw_native(env,bprintf("Can't find some fields in Java class.")); } } @@ -71,6 +73,11 @@ Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm) { msg_comm_t comm; comm = (msg_comm_t) (long) (*env)->GetLongField(env, jcomm, jcomm_field_Comm_bind); + jboolean finished = (*env)->GetBooleanField(env, jcomm, jcomm_field_Comm_finished); + if (finished == JNI_TRUE) { + return JNI_TRUE; + } + if (!comm) { jxbt_throw_native(env,bprintf("comm is null")); return JNI_FALSE; @@ -104,6 +111,12 @@ Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble tim jxbt_throw_native(env,bprintf("comm is null")); return; } + + jboolean finished = (*env)->GetBooleanField(env, jcomm, jcomm_field_Comm_finished); + if (finished == JNI_TRUE) { + return; + } + MSG_error_t status; TRY { status = MSG_comm_wait(comm,(double)timeout); @@ -111,6 +124,7 @@ Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble tim CATCH_ANONYMOUS { return; } + (*env)->SetBooleanField(env, jcomm, jcomm_field_Comm_finished, JNI_TRUE); if (status == MSG_OK) { jcomm_bind_task(env,jcomm); return; -- 2.20.1