-/*
- * $Id$
- *
- * Copyright 2006,2007 Martin Quinson, Malek Cherier All right 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.
- *
- * This contains the implementation of the wrapper functions used to interface
- * the java object with the native functions of the MSG API.
- */
+/* Java Wrappers to the MSG API. */
+
+/* Copyright (c) 2007, 2008, 2009, 2010. 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. */
+
#include "msg/msg.h"
#include "msg/private.h"
#include "simix/private.h"
/* bind & store the task */
jtask_bind(jtask, task, env);
-
- /* allocate a new global reference to the java task instance */
- task->data = (void *) jtask_new_global_ref(jtask, env);
-
- if (!task->data)
- jxbt_throw_jni(env, "global ref allocation failed");
-
+ task->data = jtask;
}
JNIEXPORT void JNICALL
jxbt_check_res("MSG_task_destroy()",rv,MSG_OK,
bprintf("unexpected error , please report this bug"));
-
-
- /* delete the global reference to the java task object */
- jtask_delete_global_ref(jtask, env);
}
JNIEXPORT void JNICALL
return;
}
+ /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
+ task->data = (void *) (*env)->NewGlobalRef(env, jtask);
rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout);
(*env)->ReleaseStringUTFChars(env, jalias, alias);
alias = (*env)->GetStringUTFChars(env, jalias, 0);
+ /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
+ task->data = (void *) (*env)->NewGlobalRef(env, jtask);
rv = MSG_task_send_bounded(task, alias, (double) jmaxRate);
(*env)->ReleaseStringUTFChars(env, jalias, alias);
MSG_error_t rv;
m_task_t task = NULL;
m_host_t host = NULL;
+ jobject jtask_global, jtask_local;
const char *alias;
if (jhost) {
alias = (*env)->GetStringUTFChars(env, jalias, 0);
rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
+ jtask_global = task->data;
+
+ /* Convert the global ref into a local ref so that the JVM can free the stuff */
+ jtask_local = (*env)->NewLocalRef(env, jtask_global);
+ (*env)->DeleteGlobalRef(env, jtask_global);
+ task->data = NULL;
(*env)->ReleaseStringUTFChars(env, jalias, alias);
jxbt_check_res("MSG_task_receive_ext()",rv, MSG_HOST_FAILURE|MSG_TRANSFER_FAILURE|MSG_TIMEOUT,
bprintf("while receiving from mailbox %s",alias));
- return (jobject) task->data;
+ return (jobject) jtask_local;
}
JNIEXPORT jboolean JNICALL