X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4d4f20d4287b144f73dae8195c5f2ba134b72e64..ff976abdc0f201064cd0fb608c39990ba2656561:/src/bindings/java/jmsg_comm.cpp diff --git a/src/bindings/java/jmsg_comm.cpp b/src/bindings/java/jmsg_comm.cpp index 9570c3c869..96ddecf03d 100644 --- a/src/bindings/java/jmsg_comm.cpp +++ b/src/bindings/java/jmsg_comm.cpp @@ -120,3 +120,50 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, job jmsg_throw_status(env,status); } } + +static msg_comm_t* jarray_to_commArray(JNIEnv *env, jobjectArray jcomms, /* OUT */ int *count) +{ + *count = env->GetArrayLength(jcomms); + msg_comm_t* comms = xbt_new(msg_comm_t, *count); + + for (int i=0; i < *count; i++) { + jobject jcomm = env->GetObjectArrayElement(jcomms, i); + if (env->ExceptionOccurred()) + break; + + comms[i] = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind); + if (!comms[i]) { + jxbt_throw_native(env,bprintf("comm at rank %d is null",i)); + return nullptr; + } + + env->DeleteLocalRef(jcomm); // reduce the load on the garbage collector: we don't need that object anymore + } + return comms; +} +JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitAll(JNIEnv *env, jclass cls, jobjectArray jcomms, jdouble timeout) +{ + int count; + msg_comm_t* comms = jarray_to_commArray(env, jcomms, &count); + if (!comms) + return; + + MSG_comm_waitall(comms, count, static_cast(timeout)); + xbt_free(comms); +} +JNIEXPORT int JNICALL Java_org_simgrid_msg_Comm_waitAny(JNIEnv *env, jclass cls, jobjectArray jcomms) +{ + int count; + msg_comm_t* comms = jarray_to_commArray(env, jcomms, &count); + if (!comms) + return -1; + xbt_dynar_t dyn = xbt_dynar_new(sizeof(msg_comm_t),nullptr); + for (int i=0; i