X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1389081a779efc2c9408010aa9c342de32423b72..ed49d3fb7b2cab0c93fb3e1d686e3041598b70d4:/src/smx_context_java.c diff --git a/src/smx_context_java.c b/src/smx_context_java.c index fc0af4e173..c91e1d96f7 100644 --- a/src/smx_context_java.c +++ b/src/smx_context_java.c @@ -27,7 +27,7 @@ static void smx_ctx_java_free(smx_context_t context); static void smx_ctx_java_start(smx_context_t context); static void smx_ctx_java_suspend(smx_context_t context); static void smx_ctx_java_resume(smx_context_t new_context); -static void smx_ctx_java_runall(xbt_dynar_t processes); +static void smx_ctx_java_runall(void); void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory) { @@ -81,54 +81,37 @@ static void smx_ctx_java_free(smx_context_t context) if (context) { smx_ctx_java_t ctx_java = (smx_ctx_java_t) context; - if (ctx_java->jprocess) { + if (ctx_java->jprocess) { /* the java process still exists */ jobject jprocess = ctx_java->jprocess; - ctx_java->jprocess = NULL; - /* if the java process is alive join it */ - if (jprocess_is_alive(jprocess, get_current_thread_env())) - jprocess_join(jprocess, get_current_thread_env()); + /* stop it */ + XBT_DEBUG("The process still exists, making it exit now"); + jprocess_exit(jprocess, get_current_thread_env()); + + /* it's dead now, remove it from the JVM */ + jprocess_delete_global_ref(jprocess, get_current_thread_env()); } } smx_ctx_base_free(context); } + void smx_ctx_java_stop(smx_context_t context) { - jobject jprocess = NULL; - XBT_DEBUG("XXXX Context Stop\n"); - + xbt_assert(context == my_current_context, + "The context to stop must be the current one"); + /* I am the current process and I am dying */ + smx_ctx_base_stop(context); - smx_ctx_java_t ctx_java; - - ctx_java = (smx_ctx_java_t) context; + XBT_DEBUG("I am dying"); - /*FIXME: is this really necessary? Seems to. */ - if (my_current_context->iwannadie) { - XBT_INFO("I wannadie"); - /* The maestro call xbt_context_stop() with an exit code set to one */ - if (ctx_java->jprocess) { - /* if the java process is alive schedule it */ - if (jprocess_is_alive(ctx_java->jprocess, get_current_thread_env())) { - jprocess_schedule(my_current_context); - jprocess = ctx_java->jprocess; - ctx_java->jprocess = NULL; - - /* interrupt the java process */ - jprocess_exit(jprocess, get_current_thread_env()); - } - } - } else { - /* the java process exits */ - jprocess = ctx_java->jprocess; - ctx_java->jprocess = NULL; - } - - /* delete the global reference associated with the java process */ - jprocess_delete_global_ref(jprocess, get_current_thread_env()); + /* suspend myself again, smx_ctx_java_free() will destroy me later + * from maeastro */ + jprocess_unschedule(context); + XBT_INFO("Java stop finished"); } static void smx_ctx_java_suspend(smx_context_t context) @@ -143,13 +126,13 @@ static void smx_ctx_java_resume(smx_context_t new_context) jprocess_schedule(new_context); } -static void smx_ctx_java_runall(xbt_dynar_t processes) +static void smx_ctx_java_runall(void) { + xbt_dynar_t processes = SIMIX_process_get_runnable(); XBT_DEBUG("XXXX Run all\n"); smx_process_t process; smx_context_t old_context; unsigned int cursor; - xbt_dynar_foreach(processes, cursor, process) { old_context = my_current_context; my_current_context = SIMIX_process_get_context(process);