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);
(*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;
(*factory)->name = "smx_ruby_context_factory";
ruby_init();
ruby_init_loadpath();
- DEBUG0("SIMIX_ctx_ruby_factory_init...Done");
}
static int smx_ctx_ruby_factory_finalize(smx_context_factory_t *factory) {
smx_ctx_ruby_t context = xbt_new0(s_smx_ctx_ruby_t,1);
- /*if the user provided a function for the process , then use it
- Otherwise it's the context for maestro */
+ /* if the user provided a function for the process , then use it
+ Otherwise it's the context for maestro */
if (code) {
context->cleanup_func = cleanup_func;
context->cleanup_arg = cleanup_arg;
context->process = (VALUE)code;
+ context->argc=argc;
+ context->argv=argv;
- DEBUG0("smx_ctx_ruby_create_context...Done");
+ DEBUG1("smx_ctx_ruby_create_context(%s)...Done",argv[0]);
}
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;
- }*/
- free (context);
- context = NULL;
- DEBUG0("smx_ctx_ruby_free_context...Done");
-}
-
-static void smx_ctx_ruby_start(smx_context_t context) {
- /* 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 Waitin' For Mutex Signal to Execute The Main*/
-
}
static void smx_ctx_ruby_stop(smx_context_t context) {
-
+ DEBUG0("smx_ctx_ruby_stop()");
VALUE process = Qnil;
smx_ctx_ruby_t ctx_ruby,current;
(*(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
}
}
} else {
- process = ctx_ruby->process;
- ctx_ruby->process = Qnil;
+
+ if (ctx_ruby->process)
+ ctx_ruby->process = Qnil;
+
}
- DEBUG0("smx_ctx_ruby_stop...Done\n");
}
static void smx_ctx_ruby_suspend(smx_context_t context) {
- if (context) {
+ DEBUG1("smx_ctx_ruby_suspend(%s)",context->argv[0]);
smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) context;
if (ctx_ruby->process)
rb_process_unschedule(ctx_ruby->process);
- DEBUG0("smx_ctx_ruby_unschedule...Done");
- } else
- rb_raise(rb_eRuntimeError,"smx_ctx_ruby_suspend failed");
}
-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) {
+ 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);
- DEBUG0("smx_ctx_ruby_schedule...Done");
}
-