Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Still have to kill runnin' processes (on simix level)and clean ruby world when nothi...
authorcoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 8 Mar 2010 16:06:38 +0000 (16:06 +0000)
committercoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 8 Mar 2010 16:06:38 +0000 (16:06 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7206 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/bindings/ruby/MasterSlave.rb
src/bindings/ruby/rb_application_handler.c
src/bindings/ruby/rb_msg_process.c
src/bindings/ruby/rb_msg_task.c
src/bindings/ruby/simgrid.rb
src/bindings/ruby/simgrid_ruby.c

index 377a530..1b0344f 100644 (file)
@@ -11,6 +11,7 @@ include MSG
 
 class Master < MSG::Process  
   # main : that function that will be executed when Running Simulation
+
   def main(args) # args is an array containing arguments for function master
    size = args.size
    for i in 0..size-1
@@ -43,6 +44,7 @@ class Master < MSG::Process
      finalize_task.send(mailbox)
    end
    MSG::info("Master : Everything's Done")
+   Thread.list.each {|t| p t}
   end    
 end
 
@@ -50,6 +52,7 @@ end
 # Class Slave
 #################################################
 class Slave < MSG::Process
+
   def main(args)
     mailbox = "slave " + args[0]
     for i in 0..args.size-1
@@ -66,12 +69,12 @@ class Slave < MSG::Process
        end
        MSG::info("Slave " + mailbox + " ...Processing" + task.name)
        task.execute
+       MSG::info("task "+ task.name + " Executed !!")
     end
     MSG::info("Slave " + mailbox +  "I'm Done , See You !!")
   end    
 end
 
-
 #################################################
 # main chunck
 #################################################
@@ -85,7 +88,8 @@ else
   #Thread.list.each {|t| p t}
 end
 
-# Thread.list.each {|t| p t}
 MSG.run
+Thread.list.each {|t| p t}
 puts "Simulation time : " + MSG.getClock .to_s
+
 # exit()
index 02802e1..63e465a 100644 (file)
@@ -52,7 +52,8 @@ static void rb_process_create_with_args(VALUE fct_name,VALUE arguments,VALUE pro
     free(process);
     rb_raise(rb_eRuntimeError,"Host not bound while creating native process");
   }
-  process->simdata->PID = msg_global->PID++; //  msg_global ??
+
+  process->simdata->PID = msg_global->PID++; 
 
   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,
@@ -85,12 +86,18 @@ static void rb_process_create_with_args(VALUE fct_name,VALUE arguments,VALUE pro
 
 void rb_application_handler_on_start_document(void) {
   
+
+   args = rb_ary_new();  // Max lenght = 16 !!
+   prop = rb_ary_new();
+
 }
 
 void rb_application_handler_on_end_document(void) {
 
-  //application_handler_class = Qnil; FIXME: probably leaking
-  
+  args = Qnil;
+  prop = Qnil;
+  function_name = Qnil;
+  host_name = Qnil;  
 }
 
 void rb_application_handler_on_begin_process(void) {
@@ -110,6 +117,7 @@ void rb_application_handler_on_process_arg(void) {
 }
 
 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);
   int i_id = NUM2INT (id);
@@ -117,11 +125,8 @@ void rb_application_handler_on_property(void) {
 
 }
 
-
 void rb_application_handler_on_end_process(void) {
 
   rb_process_create_with_args(function_name,args,prop,host_name);
     
 }
-
-
index b4fa038..e6334cb 100644 (file)
@@ -30,7 +30,6 @@ VALUE rb_process_getBind(VALUE ruby_process) {
   return rb_funcall(ruby_process,rb_intern("getBind"),0);
 }
 
-
 // Set Bind
 void rb_process_setBind(VALUE ruby_process,long bind) {
   VALUE r_bind = LONG2FIX(bind);
@@ -62,13 +61,12 @@ void rb_process_schedule( VALUE ruby_process ) {
   rb_funcall(ruby_process,rb_intern("schedule"),0);
 }
 
-/***************************************************
 
+/***************************************************
 Function for Native Process ( Bound ) Management
 
 Methods Belong to MSG Module
-
- ****************************************************/
+****************************************************/
 
 // Process To Native
 m_process_t rb_process_to_native(VALUE ruby_process) {
@@ -122,7 +120,6 @@ VALUE rb_process_isSuspended(VALUE class,VALUE ruby_process) {
     rb_raise (rb_eRuntimeError,"Process not Bound...while testing if suspended");
     return Qfalse;
   }
-
   if(MSG_process_is_suspended(process))
     return Qtrue;
   return Qfalse;
index ad934b4..8ae106a 100644 (file)
@@ -12,7 +12,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby);
 
 // Free Method
 void rb_task_free(m_task_t tk) {
-  MSG_task_destroy(tk);
+  //MSG_task_destroy(tk); ( This cause a bug !! is it really necessary ?!! not really sure !! )
 }
 
 // New Method
index 67c7e1c..eea2fa9 100644 (file)
@@ -1,16 +1,20 @@
-# FIXME: add license like in C files
-
+#  Task-related bindings to ruby  */
+# 
+#  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_ruby'
 require 'thread'
 
-###########################################################################
+##########################################################
 # Class Semaphore 
-###########################################################################
+##########################################################
 class MySemaphore
    Thread.abort_on_exception = true
     attr_accessor :permits
 
-   
   def initialize (permits = 0)
        @permits = permits
   end
@@ -87,17 +91,17 @@ class MSG::Process < Thread
   @@nextProcessId = 0
 
 # Attributes
-  attr_reader :bind, :id, :name, :pargs ,:properties# Read only
+  attr_reader :name, :pargs ,:properties, :cv, :mutex  # Read only
   
     def initialize(*args)
       super(){
        
      raise "Bad number of arguments to create a Ruby process. Expected (name,args,prop) " if args.size < 3
      
-    @cv = ConditionVariable.new
-    @mutex = Mutex.new
-    @schedBegin = Semaphore.new(0)
-    @schedEnd = Semaphore.new(0)    
+    @cv = ConditionVariable.new
+    @mutex = Mutex.new
+    @schedBegin = MySemaphore.new(0)
+    @schedEnd = MySemaphore.new(0)    
     @id = @@nextProcessId
     @@nextProcessId +=1
     @name = args[0]
@@ -114,34 +118,37 @@ class MSG::Process < Thread
   end
      
   def start()
-    @schedBegin.acquire()
+     @schedBegin.acquire(@mutex,@cv)
+
     MSG::debug("Let's execute the main() of the Ruby process")
     main(@pargs)
+<<<<<<< .mine
+#     processExit(self) # FIXME : Fix the simix_context_ruby_stop to stop context process before quitting
+    @schedEnd.release(@mutex,@cv)
+    
+=======
     @schedEnd.release()
+>>>>>>> .r7205
     MSG::debug("Released my schedEnd, bailing out")
     processExit(self) # Exit the Native Process
   end
     
-
-  # FIXME: useless, there is an attribute for bind (or the attribute is useless)
-  # Get Bind
   def getBind()
     return @bind
   end
-  
-  # Set Binds FIXME: same
+   
   def setBind(bind)
     @bind = bind
   end
     
   def unschedule()
-    @schedEnd.release()
-    @schedBegin.acquire()
+    @schedEnd.release(@mutex,@cv)
+    @schedBegin.acquire(@mutex,@cv)
   end
   
-  def schedule()
-    @schedBegin.release()
-    @schedEnd.acquire()
+  def schedule()   
+    @schedBegin.release(@mutex,@cv)
+    @schedEnd.acquire(@mutex,@cv)
   end
   
   def pause()
@@ -184,12 +191,7 @@ class MSG::Task < MSG::RbTask
     super(self,mailbox)
   end
   
-#   FIXME : this method should be associated to the class !! it return a task
-# FIXME: simply killing this adapter method should do the trick 
-  def receive(mailbox)
-    super(self,mailbox)
-  end
-  
+
   def source
     super(self)
   end
@@ -211,9 +213,9 @@ class MSG::Task < MSG::RbTask
   end
 end  
 
-############################################
+####################################################
 # Host Extend from the native Class RbHost
-############################################
+####################################################
 class MSG::Host < MSG::RbHost
 
   def getByName(name)
index 393fec7..ca4bb74 100644 (file)
@@ -65,16 +65,17 @@ static void msg_run(VALUE class) {
   DEBUG0
   ("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
   /* Cleanup Ruby hosts */
-  DEBUG0("Clean Ruby World");
+  DEBUG0("Clean Ruby World (TODO) ");
   hosts = MSG_get_host_table();
   host_count = MSG_get_host_number();
   for (cpt=0;cpt<host_count;cpt++) {
-    rbHost = (VALUE)((hosts[cpt])->data);// ??!!
+    rbHost = (VALUE)((hosts[cpt])->data);
   }
-
-  if (MSG_OK != MSG_clean()){
+  
+  //FIXME  Before Cleanin' up , we should stop process running to avoir a ThreadError
+ /* if (MSG_OK != MSG_clean()){
     rb_raise(rb_eRuntimeError,"MSG_clean() failed");
-  }
+  }*/
   return;
 }
 
@@ -128,33 +129,13 @@ static void msg_debug(VALUE class,VALUE msg) {
   DEBUG1("%s",s);
 }
 
-// Get Clock FIXME: return the double instead of float
+// get Clock
 static VALUE msg_get_clock(VALUE class) {
 
   return rb_float_new(MSG_get_clock());
 
 }
 
-// Ruby intropspection : Instanciate a ruby Class From its Name
-// Used by ProcessFactory::createProcess
-
-// FIXME: KILLME?
-static VALUE msg_new_ruby_instance(VALUE class,VALUE className) {
-  ruby_init();
-  ruby_init_loadpath();
-  char * p_className = RSTRING(className)->ptr;
-
-  return rb_funcall3(rb_const_get(rb_cObject, rb_intern(p_className)),rb_intern("new"),0, 0);
-}
-
-//This Time With Args FIXME: KILLME
-static VALUE msg_new_ruby_instance_with_args(VALUE class,VALUE className,VALUE args) {
-  ruby_init();
-  ruby_init_loadpath();
-  char * p_className = RSTRING(className)->ptr;
-  return rb_funcall(rb_const_get(rb_cObject, rb_intern(p_className)),rb_intern("new"), 1, args);
-}
-
 
 extern const char*xbt_ctx_factory_to_use; /*Hack: let msg load directly the right factory */
 
@@ -164,7 +145,7 @@ void Init_simgrid_ruby() {
 
   // Modules
   rb_msg = rb_define_module("MSG");
-  //Associated Environment Methods!
+  //Associated Environment Methods
   rb_define_module_function(rb_msg,"init",(rb_meth)msg_init,1);
   rb_define_module_function(rb_msg,"run",(rb_meth)msg_run,0);
   rb_define_module_function(rb_msg,"createEnvironment",(rb_meth)msg_createEnvironment,1);
@@ -172,14 +153,13 @@ void Init_simgrid_ruby() {
   rb_define_module_function(rb_msg,"info",(rb_meth)msg_info,1);
   rb_define_module_function(rb_msg,"debug",(rb_meth)msg_debug,1);
   rb_define_module_function(rb_msg,"getClock",(rb_meth)msg_get_clock,0);
-  rb_define_module_function(rb_msg,"rubyNewInstance",(rb_meth)msg_new_ruby_instance,1);
-  rb_define_module_function(rb_msg,"rubyNewInstanceArgs",(rb_meth)msg_new_ruby_instance_with_args,2);
 
-  // Associated Process Methods
+  //Associated Process Methods
   rb_define_method(rb_msg,"processSuspend",(rb_meth)rb_process_suspend,1);
   rb_define_method(rb_msg,"processResume",(rb_meth)rb_process_resume,1);
   rb_define_method(rb_msg,"processIsSuspend",(rb_meth)rb_process_isSuspended,1);
   rb_define_method(rb_msg,"processKill",(rb_meth)rb_process_kill_up,1);
+  rb_define_method(rb_msg,"processKillDown",(rb_meth)rb_process_kill_down,1);
   rb_define_method(rb_msg,"processGetHost",(rb_meth)rb_process_getHost,1);
   rb_define_method(rb_msg,"processExit",(rb_meth)rb_process_exit,1);
 
@@ -187,7 +167,7 @@ void Init_simgrid_ruby() {
   rb_task = rb_define_class_under(rb_msg,"RbTask",rb_cObject);
   rb_host = rb_define_class_under(rb_msg,"RbHost",rb_cObject);
 
-  //Task Methods FIXME: Convert to methods
+  //Task Methods 
   rb_define_module_function(rb_task,"new",(rb_meth)rb_task_new,3);
   rb_define_module_function(rb_task,"compSize",(rb_meth)rb_task_comp,1);
   rb_define_module_function(rb_task,"name",(rb_meth)rb_task_name,1);
@@ -207,4 +187,4 @@ void Init_simgrid_ruby() {
   rb_define_module_function(rb_host,"setData",(rb_meth)rb_host_set_data,2);
   rb_define_module_function(rb_host,"getData",(rb_meth)rb_host_get_data,1);
   rb_define_module_function(rb_host,"isAvail",(rb_meth)rb_host_is_avail,1);
-}
+}
\ No newline at end of file