*/
#include "msg/msg.h"
#include "msg/private.h"
+#include "simix/private.h"
#include "java/jxbt_context.h"
#include "jmsg_process.h"
#include "jmsg.h"
+static JavaVM * __java_vm = NULL;
+
#ifdef WIN32
static DWORD __current_thread_id = 0;
}
#endif
+JavaVM *
+get_java_VM(void) {
+ return __java_vm;
+}
+
+JNIEnv *
+get_current_thread_env(void) {
+ JNIEnv *env;
+
+ (*__java_vm)->AttachCurrentThread(__java_vm, (void **)&env, NULL);
+
+ return env;
+}
+
/*
* The MSG process connected functions implementation.
return;
}
- /* bind the java process instance to the native host */
+ /* bind the java process instance to the native process */
jprocess_bind(jprocess,process,env);
/* build the C name of the process */
env);
SIMIX_jprocess_create(process->name,
- process->simdata->m_host->simdata->s_host,
+ process->simdata->m_host->simdata->smx_host,
/*data*/ (void*)process,
- jprocess_arg,env,
- __MSG_process_cleanup,
+ jprocess,env,
&process->simdata->s_process);
DEBUG1("context created (s_process=%p)",process->simdata->s_process);
process->simdata->last_errno = MSG_OK;
-
-#ifdef KILLME
- /* add the process in the list of the process of the host */
- xbt_fifo_unshift(host->simdata->process_list, process);
-
- self = msg_global->current_process;
-
- process->simdata->context->env = env;
-
- /* start the java process */
- xbt_context_start(process->simdata->context);
-
- msg_global->current_process = self;
-#endif
-
/* add the process to the list of the processes of the simulation */
xbt_fifo_unshift(msg_global->process_list, process);
- /* add the process to the list of the processes to run in the simulation */
- // xbt_fifo_unshift(msg_global->process_to_run, process);
-
- // PAJE_PROCESS_NEW(process);
- //#endif
}
JNIEXPORT void JNICALL
jdouble jcomputeDuration, jdouble jmessageSize) {
m_task_t task; /* the native task to create */
const char* name; /* the name of the task */
-
+
if(jcomputeDuration < 0) {
jxbt_throw_illegal(env,bprintf("Task ComputeDuration (%f) cannot be negative",
(double)jcomputeDuration));
if ( ! task->data )
jxbt_throw_jni(env,"global ref allocation failed");
+
}
JNIEXPORT void JNICALL
jobject jtask;
if(!task){
- jxbt_throw_notbound(env,"task",jtask);
+ jxbt_throw_notbound(env,"task",task);
return;
}
jtask = (jobject)task->data;
JNIEXPORT void JNICALL
Java_simgrid_msg_Msg_channelPut(JNIEnv* env, jclass cls,
jobject jchannel, jobject jtask, jobject jhost) {
-
+
if(MSG_OK != MSG_task_put(jtask_to_native_task(jtask,env),
jhost_get_native(env,jhost),
(int)jchannel_get_id(jchannel,env)))
jxbt_throw_notbound(env,"task",jtask);
return;
}
-
+
if(MSG_OK != MSG_task_put_with_timeout(task,host,id,(double)jtimeout))
jxbt_throw_native(env, xbt_strdup("MSG_task_put_with_timeout() failed"));
}
#else
__current_thread_id = pthread_self();
#endif
+
+(*env)->GetJavaVM(env,&__java_vm);
}
/* Run everything */
if(MSG_OK != MSG_main())
- jxbt_throw_native(env, xbt_strdup("MSG_main() failed"));
-
+ jxbt_throw_native(env, xbt_strdup("MSG_main() failed"));
+
DEBUG0("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
- SIMIX_display_process_status();
- exit(0); /* FIXME */
-
+
DEBUG0("Clean java world");
/* Cleanup java hosts */
xbt_fifo_foreach(msg_global->host,item,host,m_host_t) {
jhost = (jobject)host->data;
if(jhost)
- jhost_unref(env,jhost);
+ jhost_unref(env,jhost);
}
+
DEBUG0("Clean native world");
/* cleanup native stuff */
if(MSG_OK != MSG_clean())
JNIEXPORT void JNICALL
Java_simgrid_msg_Msg_waitSignal(JNIEnv* env, jclass cls, jobject jprocess) {
- m_process_t m_process = jprocess_to_native_process(jprocess,env);
- smx_process_t s_process;
-
- xbt_mutex_t ctx_mutex, creation_mutex;
- xbt_thcond_t ctx_cond, creation_cond;
-
- DEBUG3("Msg_waitSignal(m_process=%p %s/%s)",
- m_process,m_process->name,m_process->simdata->m_host->name);
- if (!m_process){
- jxbt_throw_notbound(env,"process",jprocess);
- return;
- }
-
- s_process = m_process->simdata->s_process;
-
- if (s_process == NULL) {
- jxbt_throw_notbound(env,"SIMIX process",jprocess);
- return;
- }
- ctx_mutex = SIMIX_process_get_jmutex(s_process);
- ctx_cond = SIMIX_process_get_jcond(s_process);
-
- creation_mutex = xbt_creation_mutex_get();
- creation_cond = xbt_creation_cond_get();
-
- xbt_mutex_lock(creation_mutex);
- xbt_mutex_lock(ctx_mutex);
- xbt_thcond_signal( creation_cond );
- xbt_mutex_unlock( creation_mutex );
- xbt_thcond_wait(ctx_cond, ctx_mutex);
- xbt_mutex_unlock(ctx_mutex);
}
JNIEXPORT void JNICALL
Java_simgrid_msg_Msg_processExit(JNIEnv* env, jclass cls, jobject jprocess) {
+
m_process_t process = jprocess_to_native_process(jprocess,env);
if (!process){
jxbt_throw_notbound(env,"process",jprocess);
return;
}
- MSG_process_kill(process);
+
+ jcontext_exit(process->simdata->s_process->simdata->context,0,get_current_thread_env());
}
JNIEXPORT void JNICALL