From ed95f6aa5479b9dab84fd9e2e303fdc63a9089af Mon Sep 17 00:00:00 2001 From: mquinson Date: Tue, 2 Mar 2010 00:29:28 +0000 Subject: [PATCH 1/1] some more cleanups in ruby bindings. Still not working damnit (but getting clearer) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7157 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/bindings/ruby/ApplicationHandler.rb | 9 - src/bindings/ruby/MasterSlave.rb | 24 +- src/bindings/ruby/rb_application_handler.c | 43 +--- src/bindings/ruby/rb_msg_process.c | 30 +-- src/bindings/ruby/rb_msg_task.c | 4 +- src/bindings/ruby/simgrid.rb | 253 ++++++--------------- src/bindings/ruby/simgrid_ruby.c | 23 +- src/msg/msg_mailbox.c | 13 +- src/simix/smx_context_ruby.c | 34 +-- 9 files changed, 141 insertions(+), 292 deletions(-) delete mode 100644 src/bindings/ruby/ApplicationHandler.rb diff --git a/src/bindings/ruby/ApplicationHandler.rb b/src/bindings/ruby/ApplicationHandler.rb deleted file mode 100644 index 953f738fff..0000000000 --- a/src/bindings/ruby/ApplicationHandler.rb +++ /dev/null @@ -1,9 +0,0 @@ -# -# Copyright 2010. The SimGrid Team. 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. - -require 'simgrid' -include MSG -$DEBUG = false diff --git a/src/bindings/ruby/MasterSlave.rb b/src/bindings/ruby/MasterSlave.rb index 9b1cbe64ea..6f809f290f 100644 --- a/src/bindings/ruby/MasterSlave.rb +++ b/src/bindings/ruby/MasterSlave.rb @@ -5,7 +5,7 @@ include MSG # Class Master ################################################# -class Master < RbProcess +class Master < MsgProcess def initialize2() super() end @@ -30,12 +30,12 @@ class Master < RbProcess for i in 0..numberOfTask-1 - task = RbTask.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize ); + task = Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize ); s_alias = "slave>>" + (i%slaveCount).to_s - info("Master Sending "+ RbTask.name(task) + " to " + s_alias + " with Comput Size " + RbTask.compSize(task).to_s) - RbTask.send(task,s_alias) - info("Master Done Sending " +RbTask.name(task) + " to " + s_alias) -# sameTask = RbTask.receive(s_alias) + info("Master Sending "+ Task.name(task) + " to " + s_alias + " with Comput Size " + Task.compSize(task).to_s) + Task.send(task,s_alias) + info("Master Done Sending " +Task.name(task) + " to " + s_alias) +# sameTask = Task.receive(s_alias) # puts "Master Receiving its Own Task" end @@ -44,7 +44,7 @@ class Master < RbProcess for i in 0..slaveCount-1 s_alias = "slave " + i.to_s info ("Master Sending Finalize to " + s_alias) - RbTask.send(RbTask.new("finalize",0,0),s_alias) + Task.send(Task.new("finalize",0,0),s_alias) end info("Master : Everything's Done") end @@ -53,7 +53,7 @@ end ################################################# # Class Slave ################################################# -class Slave < RbProcess +class Slave < MsgProcess def initialize() super() @@ -67,15 +67,15 @@ class Slave < RbProcess while true info("Ready to Receive Task") - task = RbTask.receive(s_mailbox) - task_name = RbTask.name(task) + task = Task.receive(s_mailbox) + task_name = Task.name(task) info ("Task Received : " + task.name) if (task_name == "finalize") info("Slave" + s_mailbox + "got finalize msg") break end - info("Slave " + s_mailbox + " ...Processing" + RbTask.name(task)) - RbTask.execute(task) + info("Slave " + s_mailbox + " ...Processing" + Task.name(task)) + Task.execute(task) end info("Slave " + s_mailbox + "I'm Done , See You !!") end diff --git a/src/bindings/ruby/rb_application_handler.c b/src/bindings/ruby/rb_application_handler.c index aac298c446..1514d9de4d 100644 --- a/src/bindings/ruby/rb_application_handler.c +++ b/src/bindings/ruby/rb_application_handler.c @@ -7,57 +7,34 @@ #include "bindings/ruby_bindings.h" #include "surf/surfxml_parse.h" -static VALUE application_handler_class; // The Current Instance of ApplicationHandler Class ,is it the same as Current Thread ??!! - - -// #define MY_DEBUG - -static void r_init() { - ruby_init(); - ruby_init_loadpath(); - rb_require("ApplicationHandler.rb"); - -} +static VALUE application_handler_class; // The Current Instance of ApplicationHandler Class void rb_application_handler_on_start_document(void) { - - r_init(); - application_handler_class = rb_funcall3(rb_const_get(rb_cObject, rb_intern("ApplicationHandler")), rb_intern("new"), 0, 0); - rb_funcall(application_handler_class,rb_intern("onStartDocument"),0); - #ifdef MY_DEBUG - printf ("application_handler_on_start_document ...Done\n" ); - #endif - + application_handler_class = rb_funcall3(rb_const_get(rb_cObject, rb_intern("ApplicationHandler")), rb_intern("new"), 0, 0); } void rb_application_handler_on_end_document(void) { - rb_funcall(application_handler_class,rb_intern("onEndDocument"),0); + application_handler_class = Qnil; } void rb_application_handler_on_begin_process(void) { VALUE hostName = rb_str_new2(A_surfxml_process_host); VALUE function = rb_str_new2(A_surfxml_process_function); -#ifdef MY_DEBUG - printf ("On_Begin_Process: %s : %s \n",RSTRING(hostName)->ptr,RSTRING(function)->ptr); -#endif - rb_funcall(application_handler_class,rb_intern("onBeginProcess"),2,hostName,function); + rb_funcall(application_handler_class,rb_intern("onBeginProcess"),2,hostName,function); } void rb_application_handler_on_process_arg(void) { - VALUE arg = rb_str_new2(A_surfxml_argument_value); -#ifdef MY_DEBUG - printf ("On_Process_Args >> Sufxml argument value : %s\n",RSTRING(arg)->ptr); -#endif - rb_funcall(application_handler_class,rb_intern("onProcessArg"),1,arg); + VALUE arg = rb_str_new2(A_surfxml_argument_value); + rb_funcall(application_handler_class,rb_intern("onProcessArg"),1,arg); } void rb_application_handler_on_property(void) { - VALUE id = rb_str_new2(A_surfxml_prop_id); - VALUE val = rb_str_new2(A_surfxml_prop_value); - rb_funcall(application_handler_class,rb_intern("onProperty"),2,id,val); + VALUE id = rb_str_new2(A_surfxml_prop_id); + VALUE val = rb_str_new2(A_surfxml_prop_value); + rb_funcall(application_handler_class,rb_intern("onProperty"),2,id,val); } void rb_application_handler_on_end_process(void) { - rb_funcall(application_handler_class,rb_intern("onEndProcess"),0); + rb_funcall(application_handler_class,rb_intern("onEndProcess"),0); } diff --git a/src/bindings/ruby/rb_msg_process.c b/src/bindings/ruby/rb_msg_process.c index 8ec8a812a9..505b8a2465 100644 --- a/src/bindings/ruby/rb_msg_process.c +++ b/src/bindings/ruby/rb_msg_process.c @@ -11,74 +11,54 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ruby,bindings,"Ruby Bindings"); -// Init Ruby -void initRuby(void) { - ruby_init(); - ruby_init_loadpath(); -// KILLME rb_require("RubyProcess.rb"); -} - - /* * Functions for Ruby Process Management (Up Calls) */ - // get Ruby Process Name VALUE rb_process_getName(VALUE ruby_process) { - initRuby(); - // instance = rb_funcall3(rb_const_get(rb_cObject, rb_intern("RbProcess")), rb_intern("new"), 0, 0); return rb_funcall(ruby_process,rb_intern("getName"),0); - } // Get Process ID VALUE rb_process_getID(VALUE ruby_process) { - initRuby(); return rb_funcall(ruby_process,rb_intern("getID"),0); } // Get Bind VALUE rb_process_getBind(VALUE ruby_process) { - initRuby(); return rb_funcall(ruby_process,rb_intern("getBind"),0); } // Set Bind void rb_process_setBind(VALUE ruby_process,long bind) { - initRuby(); VALUE r_bind = LONG2FIX(bind); rb_funcall(ruby_process,rb_intern("setBind"),1,r_bind); } // isAlive VALUE rb_process_isAlive(VALUE ruby_process) { - initRuby(); return rb_funcall(ruby_process,rb_intern("alive?"),0); } // Kill Process void rb_process_kill_up(VALUE ruby_process) { - initRuby(); rb_funcall(ruby_process,rb_intern("kill"),0); } // join Process void rb_process_join( VALUE ruby_process ) { - initRuby(); rb_funcall(ruby_process,rb_intern("join"),0); } // unschedule Process void rb_process_unschedule( VALUE ruby_process ) { - initRuby(); rb_funcall(ruby_process,rb_intern("unschedule"),0); } // schedule Process void rb_process_schedule( VALUE ruby_process ) { - initRuby(); rb_funcall(ruby_process,rb_intern("schedule"),0); } @@ -142,19 +122,23 @@ void rb_process_create(VALUE class,VALUE ruby_process,VALUE host) { } process->simdata->PID = msg_global->PID++; // msg_global ?? - DEBUG7("fill in process %s/%s (pid=%d) %p (sd=%p , host=%p, host->sd=%p)\n", + DEBUG7("fill in process %s/%s (pid=%d) %p (sd=%p , host=%p, host->sd=%p)", process->name , process->simdata->m_host->name,process->simdata->PID, process,process->simdata, process->simdata->m_host, process->simdata->m_host->simdata); + /* FIXME: that's mainly for debugging. We could only allocate this if XBT_LOG_ISENABLED(ruby,debug) is true since I guess this leaks */ + char **argv=xbt_new(char*,2); + argv[0] = bprintf("%s@%s",process->name,process->simdata->m_host->simdata->smx_host->name); + argv[1] = NULL; process->simdata->s_process = SIMIX_process_create(process->name, (xbt_main_func_t)ruby_process, (void *) process, process->simdata->m_host->simdata->smx_host->name, - 0,NULL,NULL); + 1,argv,NULL); - DEBUG1("context created (s_process=%p)\n",process->simdata->s_process); + DEBUG1("context created (s_process=%p)",process->simdata->s_process); if (SIMIX_process_self()) { // SomeOne Created Me !! process->simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data); diff --git a/src/bindings/ruby/rb_msg_task.c b/src/bindings/ruby/rb_msg_task.c index 8af9413fa7..361765746f 100644 --- a/src/bindings/ruby/rb_msg_task.c +++ b/src/bindings/ruby/rb_msg_task.c @@ -58,7 +58,6 @@ void rb_task_send(VALUE class,VALUE task,VALUE mailbox) { // Wrap Ruby Value to m_task_t struct m_task_t tk; Data_Get_Struct(task, s_m_task_t, tk); - xbt_backtrace_display_current(); int res = MSG_task_send(tk,RSTRING(mailbox)->ptr); if(res != MSG_OK) rb_raise(rb_eRuntimeError,"MSG_task_send failed"); @@ -68,8 +67,7 @@ void rb_task_send(VALUE class,VALUE task,VALUE mailbox) { VALUE rb_task_receive(VALUE class, VALUE mailbox) { // Task m_task_t task = NULL; - INFO1("Receiving a task on mailbox %s",RSTRING(mailbox)->ptr); - xbt_backtrace_display_current(); + INFO1("Receiving a task on mailbox '%s'",RSTRING(mailbox)->ptr); MSG_task_receive(&task,RSTRING(mailbox)->ptr); INFO2("XXXXXXXXReceived a task %p %s",task,task->name); return Data_Wrap_Struct(class, 0, rb_task_free, task); diff --git a/src/bindings/ruby/simgrid.rb b/src/bindings/ruby/simgrid.rb index 90b8793591..9d0b847898 100644 --- a/src/bindings/ruby/simgrid.rb +++ b/src/bindings/ruby/simgrid.rb @@ -2,51 +2,61 @@ require 'simgrid_ruby' include MSG require 'thread' -$DEBUG = true # This is a Global Variable Useful for Debugging +$DEBUG = false # This is a Global Variable Useful for Debugging ########################################################################### # Class Semaphore ########################################################################### -class Semaphore - Thread.abort_on_exception = true - attr_accessor :permits - - def initialize ( permits ) - @permits = permits + +class Semaphore + def initialize(initvalue = 0) + @counter = initvalue + @waiting_list = [] end - - def acquire(mutex,cv) - raise "Interrupted Thread " if (!Thread.current.alive?) - mutex.synchronize { - while @permits <= 0 - cv.wait(mutex) - end - - @permits = @permits - 1 - cv.signal - } + def acquire + Thread.critical = true + if (@counter -= 1) < 0 + @waiting_list.push(Thread.current) + Thread.stop + end + self + ensure + Thread.critical = false end - - def release(mutex,cv) - mutex.synchronize{ - @permits += 1 - cv.signal - } + + def release + Thread.critical = true + begin + if (@counter += 1) <= 0 + t = @waiting_list.shift + t.wakeup if t + end + rescue ThreadError + retry + end + self + ensure + Thread.critical = false end end ######################################################################## -# Class RbProcess +# Class Process ######################################################################## -class RbProcess < Thread +class MsgProcess < Thread @@nextProcessId = 0 + # Attributes - attr_accessor :bind, :id, :properties, :name, - :pargs, :schedBegin, :schedEnd, :mutex, :cv + attr_reader :bind, :id, :pargs # Read only + attr_accessor :name, :properties # R/W # Initialize : Used from ApplicationHandler to fill it in def initialize(*args) + @schedBegin = Semaphore.new(0) + @schedEnd = Semaphore.new(0) + @properties = Hash.new() + @id = @@nextProcessId++ argc = args.size @@ -56,7 +66,6 @@ class RbProcess < Thread @bind = 0 @name = "" @pargs = Array.new() - init_var() start() if $DEBUG puts "Init Default Initializer...Nothing to do...Bye" @@ -83,9 +92,6 @@ class RbProcess < Thread puts @name end @pargs = Array.new() # No Args[] Passed in Arguments - @@nextProcessId += 1 - @id = @@nextProcessId - init_var() start() createProcess(self,host) if $DEBUG @@ -113,58 +119,35 @@ class RbProcess < Thread type = args[2].type() raise "Third argument should be an Array" if type != "Array" @pargs = args[3] - @@nextProcessId +=1 - @id = @@nextProcessId - init_var() createProcess(self,host) if $DEBUG puts "Initilize with 3 args" - end - -# sleep #keep the thread running + end } else raise "Bad number of argument: Expecting either 1, 2 or 3, but got "+argc end end - - # Init_var Called By Initialize - def init_var() - @proprieties = Hash.new() - @mutex = Mutex.new - @cv = ConditionVariable.new - # Process Synchronization Tools - @schedBegin = Semaphore.new(0) - @schedEnd = Semaphore.new(0) - end - #main - def msg_main(args) - # To Be Implemented within The Process... - # The Main Code of The Process to be Executed ... + # main + def msg_main(args) + # To be overriden by childs + raise("You must define a msg_main() function in your process, containing the code of this process") end - # Start : To keep the Process Alive and waitin' via semaphore + # Start : To keep the process alive and waiting via semaphore def start() - @schedBegin.acquire(@mutex,@cv) - #execute The Main Code of The Process ( Example Master ; Slave ...) + @schedBegin.acquire + # execute the main code of the process + debug("Begin execution") msg_main(@pargs) - processExit(self) #Exite the Native Process - @schedEnd.release(@mutex,@cv) + processExit(self) # Exit the Native Process + @schedEnd.release end -# NetxId - def nextId () - @@nextProcessId +=1 - return @@nextProcessId - end - - if $DEBUG - #Process List - def processList() - Thread.list.each {|t| p t} - end + def processList() + Thread.list.each {|t| p t} end #Get Own ID @@ -172,11 +155,6 @@ class RbProcess < Thread return @id end - # set Id - def setID(id) - @id = id - end - #Get a Process ID def processID(process) return process.id @@ -202,21 +180,17 @@ class RbProcess < Thread @bind = bind end - def unschedule() - - @schedEnd.release(@mutex,@cv) -# info("@schedEnd.release(@mutex,@cv)") - @schedBegin.acquire(@mutex,@cv) -# info("@schedBegin.acquire(@mutex,@cv)") - + def unschedule() + @schedEnd.release + @schedBegin.acquire end def schedule() - @schedBegin.release(@mutex,@cv) - @schedEnd.acquire(@mutex,@cv) + @schedBegin.release + @schedEnd.acquire end - #C Simualateur Process Equivalent Management + #C Simualator Process Equivalent Management # After Binding Ruby Process to C Process # pause @@ -249,12 +223,12 @@ end class ProcessFactory # Attributes - attr_accessor :args, :proprieties, :hostName, :function -# Initlialize + attr_accessor :args, :properties, :hostName, :function +# Initialize def initialize() @args = Array.new - @proprieties = Hash.new + @properties = Hash.new @hostName = nil @function = nil @@ -266,42 +240,37 @@ class ProcessFactory @function = function if !args.empty? - args.clear + args.clear end - if !proprieties.empty? - proprieties.clear + if !properties.empty? + properties.clear end end -# RegisterProcess def registerProcessArg(arg) - @args.push(arg) - end # CreateProcess def createProcess() - - process = rubyNewInstance(@function) # process = rubyNewInstanceArgs(@function,@args) # + process = rubyNewInstance(@function) size = @args.size for i in 0..size-1 process.pargs.push(@args[i]) end process.name = @function - process.id = process.nextId() # This increment Automaticaly The Static ProcessNextId for The Class RbProces - host = RbHost.getByName(@hostName) + host = Host.getByName(@hostName) processCreate(process,host) process.properties = @properties - @proprieties = Hash.new + @properties = Hash.new end # SetProperty def setProperty(id,value) - @proprieties[id] = value + @properties[id] = value end end @@ -310,104 +279,28 @@ end ######################################################################### class ApplicationHandler @processFactory -# Initialize - def initialize() - #Nothing todo - end - # onStartDocument - def onStartDocument() - + def initialize() @processFactory = ProcessFactory.new - if ($DEBUG) - puts "onStartDocument" - end - end -# onBeginProcess def onBeginProcess(hostName,function) - @processFactory.setProcessIdentity(hostName,function) - - if ($DEBUG) - puts "onBeginProcess" - end - + debug("onBeginProcess("+hostName+","+function+")") end -# onProperty - def onProperty(id,value) - + def onProperty(id,value) @processFactory.setProperty(id,value) - - if ($DEBUG) - puts "onProperty" - end - end -# RegisterProcessArg - def onProcessArg(arg) - + def onProcessArg(arg) @processFactory.registerProcessArg(arg) - - if ($DEBUG) - puts "onProcessArg" - end - end -# OnEndProcess - def onEndProcess() - + def onEndProcess() @processFactory.createProcess() - - if ($DEBUG) - puts "onEndProcess" - end - - end - - # onEndDocument - def onEndDocument() -# Erm... Actually nothing to do !! - - if($DEBUG) - puts "onEndDocument" - end - end - - # End Class - end - -######################### -# Class RbHost -######################### - -class RbHost < Host -# Attributes - attr_accessor :bind, :data - -# Initialize - def initialize() - super() - @bind = 0 - @data = nil + debug("onEndProcess") end - -end - -######################### -# Class RbTask -######################### -class RbTask < Task - attr_accessor :bind - - def initialize(name,comp_size,comm_size) - super(name,comp_size,comm_size) - end - end ######################### diff --git a/src/bindings/ruby/simgrid_ruby.c b/src/bindings/ruby/simgrid_ruby.c index ac65b0d781..f879214086 100644 --- a/src/bindings/ruby/simgrid_ruby.c +++ b/src/bindings/ruby/simgrid_ruby.c @@ -26,9 +26,8 @@ static void msg_init(VALUE Class,VALUE args) VALUE *ptr ; // Testing The Args Type type = TYPE(args); - if (type != T_ARRAY ) - { - rb_raise(rb_eRuntimeError,"Argh!!! Bad Arguments to msg_init"); + if (type != T_ARRAY ) { + rb_raise(rb_eRuntimeError,"Bad arguments to msg_init (expecting an array)"); return; } ptr= RARRAY(args)->ptr; @@ -37,8 +36,7 @@ static void msg_init(VALUE Class,VALUE args) argc++; argv = xbt_new0(char *, argc); argv[0] = strdup("ruby"); - for (i=0;iptr; INFO1("%s",s); } +static void msg_debug(VALUE class,VALUE msg) { + const char *s = RSTRING(msg)->ptr; + DEBUG1("%s",s); +} // Get Clock static void msg_get_clock(VALUE class) { @@ -159,9 +156,12 @@ static VALUE msg_new_ruby_instance_with_args(VALUE class,VALUE className,VALUE a } +extern const char*xbt_ctx_factory_to_use; /*Hack: let msg load directly the right factory */ typedef VALUE(*rb_meth)(ANYARGS); void Init_simgrid_ruby() { + xbt_ctx_factory_to_use = "ruby"; + // Modules rb_msg = rb_define_module("MSG"); //Associated Environment Methods! @@ -170,6 +170,7 @@ void Init_simgrid_ruby() { rb_define_method(rb_msg,"createEnvironment",(rb_meth)msg_createEnvironment,1); rb_define_method(rb_msg,"deployApplication",(rb_meth)msg_deployApplication,1); rb_define_method(rb_msg,"info",(rb_meth)msg_info,1); + rb_define_method(rb_msg,"debug",(rb_meth)msg_debug,1); rb_define_method(rb_msg,"getClock",(rb_meth)msg_get_clock,0); rb_define_method(rb_msg,"rubyNewInstance",(rb_meth)msg_new_ruby_instance,1); rb_define_method(rb_msg,"rubyNewInstanceArgs",(rb_meth)msg_new_ruby_instance_with_args,2); diff --git a/src/msg/msg_mailbox.c b/src/msg/msg_mailbox.c index 9b5cec87ea..a4ccc25670 100644 --- a/src/msg/msg_mailbox.c +++ b/src/msg/msg_mailbox.c @@ -111,9 +111,14 @@ MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t *task, m_host_t host, xbt_ex_t e; MSG_error_t ret = MSG_OK; smx_comm_t comm; + + /* We no longer support getting a task from a specific host */ + if (host) THROW_UNIMPLEMENTED; + CHECK_HOST(); memset(&comm,0,sizeof(comm)); + /* Kept for compatibility with older implementation */ xbt_assert1(!MSG_mailbox_get_cond(mailbox), "A process is already blocked on this channel %s", @@ -123,16 +128,12 @@ MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t *task, m_host_t host, xbt_assert0(task, "Null pointer for the task storage"); if (*task) - CRITICAL0 - ("MSG_task_get() was asked to write in a non empty task struct."); - - /* We no longer support getting a task from a specific host */ - if(host) - THROW_UNIMPLEMENTED; + CRITICAL0("MSG_task_get() was asked to write in a non empty task struct."); /* Try to receive it by calling SIMIX network layer */ TRY{ SIMIX_network_recv(mailbox->rdv, timeout, task, NULL, &comm); + //INFO2("Got task %s from %s",(*task)->name,mailbox->alias); (*task)->simdata->refcount--; } CATCH(e){ diff --git a/src/simix/smx_context_ruby.c b/src/simix/smx_context_ruby.c index 4ff0c80025..a580cb38ad 100644 --- a/src/simix/smx_context_ruby.c +++ b/src/simix/smx_context_ruby.c @@ -42,7 +42,6 @@ void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory) { (*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) { @@ -57,14 +56,16 @@ smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, 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; } @@ -88,19 +89,20 @@ static void smx_ctx_ruby_free(smx_context_t context) { free(context); context = NULL; }*/ + DEBUG1("smx_ctx_ruby_free_context(%s)",context->argv[0]); 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*/ - + 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]); VALUE process = Qnil; smx_ctx_ruby_t ctx_ruby,current; @@ -126,24 +128,26 @@ static void smx_ctx_ruby_stop(smx_context_t context) { process = ctx_ruby->process; ctx_ruby->process = Qnil; } - DEBUG0("smx_ctx_ruby_stop...Done\n"); + DEBUG1("smx_ctx_ruby_stop(%s)...Done",context->argv[0]); } 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) { + DEBUG2("smx_ctx_ruby_resume(%s,%s)", + (old_context->argc?old_context->argv[0]:"maestro"), + (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"); +// DEBUG1("smx_ctx_ruby_schedule(%s)...Done", +// (new_context->argc?new_context->argv[0]:"maestro")); } -- 2.20.1