Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / src / bindings / java / jmsg_task.cpp
index 5c28035..e5567f7 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions related to the java task instances.                            */
 
-/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -60,7 +60,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_create(JNIEnv * env, jobject jt
   const char *name = nullptr;      /* the name of the task                                 */
 
   if (jname)
-    name = env->GetStringUTFChars(jname, 0);
+    name = env->GetStringUTFChars(jname, nullptr);
   msg_task_t task = MSG_task_create(name, jflopsAmount, jbytesAmount, jtask);
   if (jname)
     env->ReleaseStringUTFChars(jname, name);
@@ -75,9 +75,9 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_parallelCreate(JNIEnv * env, jo
 {
   int host_count = env->GetArrayLength(jhosts);
 
-  jdouble* jcomputeDurations = env->GetDoubleArrayElements(jcomputeDurations_arg, 0);
-  msg_host_t* hosts          = new msg_host_t[host_count];
-  double* computeDurations   = new double[host_count];
+  jdouble* jcomputeDurations = env->GetDoubleArrayElements(jcomputeDurations_arg, nullptr);
+  auto* hosts                = new msg_host_t[host_count];
+  auto* computeDurations     = new double[host_count];
   for (int index = 0; index < host_count; index++) {
     jobject jhost           = env->GetObjectArrayElement(jhosts, index);
     hosts[index] = jhost_get_native(env, jhost);
@@ -85,15 +85,15 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_parallelCreate(JNIEnv * env, jo
   }
   env->ReleaseDoubleArrayElements(jcomputeDurations_arg, jcomputeDurations, 0);
 
-  jdouble* jmessageSizes = env->GetDoubleArrayElements(jmessageSizes_arg, 0);
-  double* messageSizes   = new double[host_count * host_count];
+  jdouble* jmessageSizes = env->GetDoubleArrayElements(jmessageSizes_arg, nullptr);
+  auto* messageSizes     = new double[host_count * host_count];
   for (int index = 0; index < host_count * host_count; index++) {
     messageSizes[index] = jmessageSizes[index];
   }
   env->ReleaseDoubleArrayElements(jmessageSizes_arg, jmessageSizes, 0);
 
   /* get the C string from the java string */
-  const char* name = env->GetStringUTFChars(jname, 0);
+  const char* name = env->GetStringUTFChars(jname, nullptr);
   msg_task_t task  = MSG_parallel_task_create(name, host_count, hosts, computeDurations, messageSizes, jtask);
   env->ReleaseStringUTFChars(jname, name);
 
@@ -151,7 +151,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setBound(JNIEnv * env, jobject
 }
 
 JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName(JNIEnv * env, jobject jtask) {
-  msg_task_t task = jtask_to_native(jtask, env);
+  const_msg_task_t task = jtask_to_native(jtask, env);
 
   if (not task) {
     jxbt_throw_notbound(env, "task", jtask);
@@ -162,16 +162,14 @@ JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName(JNIEnv * env, jobjec
 }
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender(JNIEnv * env, jobject jtask) {
-  msg_process_t process;
-
-  msg_task_t task = jtask_to_native(jtask, env);
+  const_msg_task_t task = jtask_to_native(jtask, env);
 
   if (not task) {
     jxbt_throw_notbound(env, "task", jtask);
     return nullptr;
   }
 
-  process = MSG_task_get_sender(task);
+  auto const* process = MSG_task_get_sender(task);
   if (process == nullptr) {
     return nullptr;
   }
@@ -180,15 +178,14 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender(JNIEnv * env, jobj
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSource(JNIEnv * env, jobject jtask)
 {
-  msg_host_t host;
-  msg_task_t task = jtask_to_native(jtask, env);
+  const_msg_task_t task = jtask_to_native(jtask, env);
 
   if (not task) {
     jxbt_throw_notbound(env, "task", jtask);
     return nullptr;
   }
 
-  host = MSG_task_get_source(task);
+  auto const* host = MSG_task_get_source(task);
   if (host == nullptr) {
     return nullptr;
   }
@@ -202,7 +199,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSource(JNIEnv * env, jobj
 
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Task_getFlopsAmount(JNIEnv * env, jobject jtask)
 {
-  msg_task_t ptask = jtask_to_native(jtask, env);
+  const_msg_task_t ptask = jtask_to_native(jtask, env);
 
   if (not ptask) {
     jxbt_throw_notbound(env, "task", jtask);
@@ -218,7 +215,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setName(JNIEnv *env, jobject jt
     jxbt_throw_notbound(env, "task", jtask);
     return;
   }
-  const char *name = env->GetStringUTFChars((jstring) jname, 0);
+  const char* name = env->GetStringUTFChars((jstring)jname, nullptr);
 
   env->SetObjectField(jtask, jtask_field_Task_name, jname);
   MSG_task_set_name(task, name);
@@ -270,9 +267,9 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_sendBounded(JNIEnv * env,jobjec
   }
 
   /* Add a global ref into the Ctask so that the receiver can use it */
-  MSG_task_set_data(task, (void *) env->NewGlobalRef(jtask));
+  MSG_task_set_data(task, env->NewGlobalRef(jtask));
 
-  const char* alias = env->GetStringUTFChars(jalias, 0);
+  const char* alias = env->GetStringUTFChars(jalias, nullptr);
   msg_error_t res   = MSG_task_send_with_timeout_bounded(task, alias, jtimeout, maxrate);
   env->ReleaseStringUTFChars(jalias, alias);
 
@@ -284,7 +281,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_receive(JNIEnv* env, jclass
 {
   msg_task_t task = nullptr;
 
-  const char *alias = env->GetStringUTFChars(jalias, 0);
+  const char* alias = env->GetStringUTFChars(jalias, nullptr);
   msg_error_t rv;
   if (not simgrid::ForcefulKillException::try_n_catch(
           [&rv, &task, &alias, &jtimeout]() { rv = MSG_task_receive_with_timeout(&task, alias, (double)jtimeout); })) {
@@ -297,7 +294,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_receive(JNIEnv* env, jclass
     jmsg_throw_status(env, rv);
     return nullptr;
   }
-  jobject jtask_global = (jobject) MSG_task_get_data(task);
+  auto jtask_global = (jobject)MSG_task_get_data(task);
 
   /* Convert the global ref into a local ref so that the JVM can free the stuff */
   jobject jtask_local = env->NewLocalRef(jtask_global);
@@ -313,7 +310,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_irecv(JNIEnv * env, jclass c
     return nullptr;
 
   //pointer to store the task object pointer.
-  msg_task_t* task = new msg_task_t(nullptr);
+  auto* task = new msg_task_t(nullptr);
   /* There should be a cache here */
 
   jobject jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
@@ -322,7 +319,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_irecv(JNIEnv * env, jclass c
     return nullptr;
   }
 
-  const char* mailbox = env->GetStringUTFChars(jmailbox, 0);
+  const char* mailbox = env->GetStringUTFChars(jmailbox, nullptr);
   msg_comm_t comm     = MSG_task_irecv(task, mailbox);
   env->ReleaseStringUTFChars(jmailbox, mailbox);
 
@@ -338,15 +335,15 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_receiveBounded(JNIEnv* env,
 {
   msg_task_t task = nullptr;
 
-  const char *alias = env->GetStringUTFChars(jalias, 0);
-  msg_error_t res   = MSG_task_receive_ext_bounded(&task, alias, jtimeout, /*host*/ nullptr, rate);
+  const char* alias = env->GetStringUTFChars(jalias, nullptr);
+  msg_error_t res   = MSG_task_receive_with_timeout_bounded(&task, alias, jtimeout, rate);
   if (env->ExceptionOccurred())
     return nullptr;
   if (res != MSG_OK) {
     jmsg_throw_status(env, res);
     return nullptr;
   }
-  jobject jtask_global = (jobject)MSG_task_get_data(task);
+  auto jtask_global = (jobject)MSG_task_get_data(task);
 
   /* Convert the global ref into a local ref so that the JVM can free the stuff */
   jobject jtask_local = env->NewLocalRef(jtask_global);
@@ -366,7 +363,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_irecvBounded(JNIEnv * env, j
     return nullptr;
 
   // pointer to store the task object pointer.
-  msg_task_t* task = new msg_task_t(nullptr);
+  auto* task = new msg_task_t(nullptr);
 
   jobject jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
   if (not jcomm) {
@@ -374,7 +371,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_irecvBounded(JNIEnv * env, j
     return nullptr;
   }
 
-  const char* mailbox = env->GetStringUTFChars(jmailbox, 0);
+  const char* mailbox = env->GetStringUTFChars(jmailbox, nullptr);
   msg_comm_t comm     = MSG_task_irecv_bounded(task, mailbox, rate);
   env->ReleaseStringUTFChars(jmailbox, mailbox);
 
@@ -395,7 +392,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isend(JNIEnv *env, jobject j
     return nullptr;
 
   jobject jcomm       = env->NewObject(comm_class, jtask_method_Comm_constructor);
-  const char* mailbox = env->GetStringUTFChars(jmailbox, 0);
+  const char* mailbox = env->GetStringUTFChars(jmailbox, nullptr);
 
   msg_task_t task = jtask_to_native(jtask, env);
 
@@ -406,7 +403,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isend(JNIEnv *env, jobject j
         return nullptr;
   }
 
-  MSG_task_set_data(task, (void *) env->NewGlobalRef(jtask));
+  MSG_task_set_data(task, env->NewGlobalRef(jtask));
   comm = MSG_task_isend(task,mailbox);
 
   env->SetLongField(jcomm, jtask_field_Comm_bind, (jlong) (uintptr_t)(comm));
@@ -431,7 +428,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isendBounded(JNIEnv *env, jo
     return nullptr;
 
   jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
-  mailbox = env->GetStringUTFChars(jmailbox, 0);
+  mailbox = env->GetStringUTFChars(jmailbox, nullptr);
 
   task = jtask_to_native(jtask, env);
 
@@ -442,7 +439,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isendBounded(JNIEnv *env, jo
         return nullptr;
   }
 
-  MSG_task_set_data(task, (void *) env->NewGlobalRef(jtask));
+  MSG_task_set_data(task, env->NewGlobalRef(jtask));
   comm = MSG_task_isend_bounded(task,mailbox,maxrate);
 
   env->SetLongField(jcomm, jtask_field_Comm_bind, (jlong) (uintptr_t)(comm));
@@ -467,10 +464,10 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_nativeFinalize(JNIEnv * env, jo
 }
 
 static void msg_task_cancel_on_failed_dsend(void*t) {
-  msg_task_t task = (msg_task_t) t;
+  auto task       = (msg_task_t)t;
   JNIEnv* env     = get_current_thread_env();
   if (env) {
-    jobject jtask_global = (jobject)MSG_task_get_data(task);
+    auto jtask_global = (jobject)MSG_task_get_data(task);
     /* Destroy the global ref so that the JVM can free the stuff */
     env->DeleteGlobalRef(jtask_global);
     /* Don't free the C data here, to avoid a race condition with the GC also sometimes doing so.
@@ -483,7 +480,7 @@ static void msg_task_cancel_on_failed_dsend(void*t) {
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsend(JNIEnv * env, jobject jtask, jstring jalias)
 {
-  const char *alias = env->GetStringUTFChars(jalias, 0);
+  const char* alias = env->GetStringUTFChars(jalias, nullptr);
 
   msg_task_t task = jtask_to_native(jtask, env);
 
@@ -494,7 +491,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsend(JNIEnv * env, jobject jta
   }
 
   /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
-  MSG_task_set_data(task, (void *) env->NewGlobalRef(jtask));
+  MSG_task_set_data(task, env->NewGlobalRef(jtask));
   MSG_task_dsend(task, alias, msg_task_cancel_on_failed_dsend);
 
   env->ReleaseStringUTFChars(jalias, alias);
@@ -503,7 +500,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsend(JNIEnv * env, jobject jta
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsendBounded(JNIEnv * env, jobject jtask, jstring jalias,
                                                               jdouble maxrate)
 {
-  const char *alias = env->GetStringUTFChars(jalias, 0);
+  const char* alias = env->GetStringUTFChars(jalias, nullptr);
 
   msg_task_t task = jtask_to_native(jtask, env);
 
@@ -514,7 +511,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsendBounded(JNIEnv * env, jobj
   }
 
   /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
-  MSG_task_set_data(task, (void *) env->NewGlobalRef(jtask));
+  MSG_task_set_data(task, env->NewGlobalRef(jtask));
   MSG_task_dsend_bounded(task, alias, msg_task_cancel_on_failed_dsend, maxrate);
 
   env->ReleaseStringUTFChars(jalias, alias);
@@ -522,7 +519,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsendBounded(JNIEnv * env, jobj
 
 JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Task_listen(JNIEnv * env, jclass cls, jstring jalias)
 {
-  const char *alias = env->GetStringUTFChars(jalias, 0);
+  const char* alias = env->GetStringUTFChars(jalias, nullptr);
   int rv = MSG_task_listen(alias);
   env->ReleaseStringUTFChars(jalias, alias);
 
@@ -531,7 +528,7 @@ JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Task_listen(JNIEnv * env, jclass
 
 JNIEXPORT jint JNICALL Java_org_simgrid_msg_Task_listenFrom(JNIEnv * env, jclass cls, jstring jalias)
 {
-  const char *alias = env->GetStringUTFChars(jalias, 0);
+  const char* alias = env->GetStringUTFChars(jalias, nullptr);
   int rv = MSG_task_listen_from(alias);
   env->ReleaseStringUTFChars(jalias, alias);