Exemplo n.º 1
0
JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm) {
  msg_comm_t comm;
  comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);

  jboolean finished = env->GetBooleanField(jcomm, jcomm_field_Comm_finished);
  if (finished == JNI_TRUE) {
    return JNI_TRUE;
  }

  if (not comm) {
    jxbt_throw_null(env, "comm is null");
    return JNI_FALSE;
  }

  if (MSG_comm_test(comm)) {
    msg_error_t status = MSG_comm_get_status(comm);
    if (status == MSG_OK) {
      jcomm_bind_task(env,jcomm);
      return JNI_TRUE;
    } else {
      //send the correct exception
      jmsg_throw_status(env,status);
    }
  }
  return JNI_FALSE;
}
Exemplo n.º 2
0
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Process_migrate(JNIEnv * env,
                                     jobject jprocess, jobject jhost)
{
  msg_process_t process = jprocess_to_native_process(jprocess, env);

  if (!process) {
    jxbt_throw_notbound(env, "process", jprocess);
    return;
  }

  msg_host_t host = jhost_get_native(env, jhost);

  if (!host) {
    jxbt_throw_notbound(env, "host", jhost);
    return;
  }

  /* try to change the host of the process */
  msg_error_t rv = MSG_process_migrate(process, host);
  if (rv != MSG_OK) {
    jmsg_throw_status(env,rv);
    return;
  }
  /* change the host java side */
  (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost);
}
Exemplo n.º 3
0
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble timeout) {
  msg_comm_t comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
  if (!comm) {
    jxbt_throw_native(env,bprintf("comm is null"));
    return;
  }

  jboolean finished = env->GetBooleanField(jcomm, jcomm_field_Comm_finished);
  if (finished == JNI_TRUE) {
    return;
  }

  msg_error_t status;
  status = MSG_comm_wait(comm,(double)timeout);
  env->SetBooleanField(jcomm, jcomm_field_Comm_finished, JNI_TRUE);
  if (status == MSG_OK) {
    jcomm_bind_task(env,jcomm);
    return;
  }
  else {
    jmsg_throw_status(env,status);
  }

}
Exemplo n.º 4
0
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_acquire(JNIEnv * env, jobject obj, jdouble timeout) {
  msg_sem_t sem;

  sem = (msg_sem_t) (uintptr_t) env->GetLongField(obj, jsyncro_field_Semaphore_bind);
  msg_error_t res = MSG_sem_acquire_timeout(sem, (double) timeout);
  if (res != MSG_OK) {
    jmsg_throw_status(env, res);
  }
}
Exemplo n.º 5
0
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess,
                                     jdouble jseconds)
{
  msg_error_t rv;
  rv = MSG_process_sleep((double)jseconds);
  if ((*env)->ExceptionOccurred(env))
    return;
  if (rv != MSG_OK) {
    XBT_DEBUG("Status NOK");
    jmsg_throw_status(env,rv);
  }
}