Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix platform file for mutual exclusion example. Fix the associated test
[simgrid.git] / src / jmsg_task.c
index d0ac22e..86fe919 100644 (file)
@@ -48,12 +48,11 @@ Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass cls) {
        jclass jtask_class_Task = (*env)->FindClass(env, "org/simgrid/msg/Task");
 
        jtask_method_Comm_constructor = (*env)->GetMethodID(env, jtask_class_Comm, "<init>", "()V");
-       //FIXME: Don't use jxbt_get_sfield directly, it is slower.
-       jtask_field_Task_bind = jxbt_get_sfield(env, "org/simgrid/msg/Task", "bind", "J");
+       jtask_field_Task_bind = jxbt_get_jfield(env, jtask_class_Task, "bind", "J");
        jtask_field_Task_name = jxbt_get_jfield(env, jtask_class_Task, "name", "Ljava/lang/String;");
-       jtask_field_Comm_bind = jxbt_get_sfield(env, "org/simgrid/msg/Comm", "bind", "J");
-       jtask_field_Comm_taskBind = jxbt_get_sfield(env, "org/simgrid/msg/Comm", "taskBind", "J");
-       jtask_field_Comm_receiving = jxbt_get_sfield(env, "org/simgrid/msg/Comm", "receiving", "Z");
+       jtask_field_Comm_bind = jxbt_get_jfield(env, jtask_class_Comm, "bind", "J");
+       jtask_field_Comm_taskBind = jxbt_get_jfield(env, jtask_class_Comm, "taskBind", "J");
+       jtask_field_Comm_receiving = jxbt_get_jfield(env, jtask_class_Comm, "receiving", "Z");
        if (!jtask_field_Task_bind || !jtask_class_Task || !jtask_field_Comm_bind || !jtask_field_Comm_taskBind ||
                  !jtask_field_Comm_receiving || !jtask_method_Comm_constructor) {
                        jxbt_throw_native(env,bprintf("Can't find some fields in Java class."));
@@ -426,8 +425,12 @@ Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls,
   }
 
   alias = (*env)->GetStringUTFChars(env, jalias, 0);
-
-  rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
+  TRY {
+       rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
+  }
+  CATCH_ANONYMOUS {
+       return NULL;
+  }
   if (rv != MSG_OK) {
        switch (rv) {
                case MSG_TIMEOUT:
@@ -576,9 +579,12 @@ Java_org_simgrid_msg_Task_listen(JNIEnv * env, jclass cls,
   int rv;
 
   alias = (*env)->GetStringUTFChars(env, jalias, 0);
-
-  rv = MSG_task_listen(alias);
-
+  TRY {
+       rv = MSG_task_listen(alias);
+  }
+  CATCH_ANONYMOUS {
+       return 0;
+  }
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
   return (jboolean) rv;
@@ -598,9 +604,12 @@ Java_org_simgrid_msg_Task_listenFromHost(JNIEnv * env, jclass cls,
     return -1;
   }
   alias = (*env)->GetStringUTFChars(env, jalias, 0);
-
-  rv = MSG_task_listen_from_host(alias, host);
-
+  TRY {
+       rv = MSG_task_listen_from_host(alias, host);
+  }
+  CATCH_ANONYMOUS {
+       return 0;
+  }
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
   return (jint) rv;
@@ -613,9 +622,12 @@ Java_org_simgrid_msg_Task_listenFrom(JNIEnv * env, jclass cls,
 
   int rv;
   const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
-
-  rv = MSG_task_listen_from(alias);
-
+  TRY {
+       rv = MSG_task_listen_from(alias);
+  }
+  CATCH_ANONYMOUS {
+       return 0;
+  }
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
   return (jint) rv;