X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ed95f6aa5479b9dab84fd9e2e303fdc63a9089af..da40a399ba4a195c4c15fb4b9a74ceb48b843df2:/src/simix/smx_context_ruby.c diff --git a/src/simix/smx_context_ruby.c b/src/simix/smx_context_ruby.c index a580cb38ad..8295eb39f0 100644 --- a/src/simix/smx_context_ruby.c +++ b/src/simix/smx_context_ruby.c @@ -21,11 +21,9 @@ smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, static int smx_ctx_ruby_factory_finalize(smx_context_factory_t *factory); static void smx_ctx_ruby_free(smx_context_t context); -static void smx_ctx_ruby_start(smx_context_t context); static void smx_ctx_ruby_stop(smx_context_t context); static void smx_ctx_ruby_suspend(smx_context_t context); -static void -smx_ctx_ruby_resume(smx_context_t old_context,smx_context_t new_context); +static void smx_ctx_ruby_resume(smx_context_t new_context); static void smx_ctx_ruby_wrapper(void); @@ -35,7 +33,6 @@ void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory) { (*factory)->create_context = smx_ctx_ruby_create_context; (*factory)->finalize = smx_ctx_ruby_factory_finalize; (*factory)->free = smx_ctx_ruby_free; - (*factory)->start = smx_ctx_ruby_start; (*factory)->stop = smx_ctx_ruby_stop; (*factory)->suspend = smx_ctx_ruby_suspend; (*factory)->resume = smx_ctx_ruby_resume; @@ -70,40 +67,26 @@ smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, return (smx_context_t) context; } +// FIXME static void smx_ctx_ruby_free(smx_context_t context) { - /* VALUE process; - if (context) - { - smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) context; - - if (ctx_ruby->process){ - // if the Ruby Process is Alive , Join it - // if ( process_isAlive(ctx_ruby->process)) - { - process = ctx_ruby->process; - ctx_ruby->process = Qnil; - process_join(process); - } - + int i; + if (context) { + DEBUG1("smx_ctx_ruby_free_context(%p)",context); + /* free argv */ + if (context->argv) { + for (i = 0; i < context->argc; i++) + if (context->argv[i]) + free(context->argv[i]); + + free(context->argv); + } + free (context); + context = NULL; } - free(context); - context = NULL; - }*/ - DEBUG1("smx_ctx_ruby_free_context(%s)",context->argv[0]); - free (context); - context = NULL; -} - -static void smx_ctx_ruby_start(smx_context_t context) { - DEBUG1("smx_ctx_ruby_start(%s) (nothing to do)",context->argv[0]); - /* Already Done .. Since a Ruby process is launched within initialization - We Start it Within the Initializer ... We Use the Semaphore To Keep - the thread alive waiting for mutex signal to execute the main*/ } static void smx_ctx_ruby_stop(smx_context_t context) { - DEBUG1("smx_ctx_ruby_stop(%s)",context->argv[0]); - + DEBUG0("smx_ctx_ruby_stop()"); VALUE process = Qnil; smx_ctx_ruby_t ctx_ruby,current; @@ -111,13 +94,14 @@ static void smx_ctx_ruby_stop(smx_context_t context) { (*(context->cleanup_func)) (context->cleanup_arg); ctx_ruby = (smx_ctx_ruby_t) context; - - // Well , Let's Do The Same as JNI Stoppin' Process + if ( simix_global->current_process->iwannadie ) { if( ctx_ruby->process ) { + //if the Ruby Process still Alive ,let's Schedule it if ( rb_process_isAlive( ctx_ruby->process ) ) { - current = (smx_ctx_ruby_t)simix_global->current_process->context; + + current = (smx_ctx_ruby_t)simix_global->current_process->context; rb_process_schedule(current->process); process = ctx_ruby->process; // interupt/kill The Ruby Process @@ -125,10 +109,11 @@ static void smx_ctx_ruby_stop(smx_context_t context) { } } } else { - process = ctx_ruby->process; - ctx_ruby->process = Qnil; + + if (ctx_ruby->process) + ctx_ruby->process = Qnil; + } - DEBUG1("smx_ctx_ruby_stop(%s)...Done",context->argv[0]); } static void smx_ctx_ruby_suspend(smx_context_t context) { @@ -139,15 +124,11 @@ static void smx_ctx_ruby_suspend(smx_context_t context) { rb_process_unschedule(ctx_ruby->process); } -static void smx_ctx_ruby_resume(smx_context_t old_context,smx_context_t new_context) { - DEBUG2("smx_ctx_ruby_resume(%s,%s)", - (old_context->argc?old_context->argv[0]:"maestro"), +static void smx_ctx_ruby_resume(smx_context_t new_context) { + DEBUG1("smx_ctx_ruby_resume(%s)", (new_context->argc?new_context->argv[0]:"maestro")); smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) new_context; rb_process_schedule(ctx_ruby->process); -// DEBUG1("smx_ctx_ruby_schedule(%s)...Done", -// (new_context->argc?new_context->argv[0]:"maestro")); } -