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
finalize_task.send(mailbox)
end
MSG::info("Master : Everything's Done")
+ Thread.list.each {|t| p t}
end
end
# Class Slave
#################################################
class Slave < MSG::Process
+
def main(args)
mailbox = "slave " + args[0]
for i in 0..args.size-1
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
#################################################
#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()
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,
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) {
}
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);
}
-
void rb_application_handler_on_end_process(void) {
rb_process_create_with_args(function_name,args,prop,host_name);
}
-
-
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);
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) {
rb_raise (rb_eRuntimeError,"Process not Bound...while testing if suspended");
return Qfalse;
}
-
if(MSG_process_is_suspended(process))
return Qtrue;
return Qfalse;
// 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
-# 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
@@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]
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()
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
end
end
-############################################
+####################################################
# Host Extend from the native Class RbHost
-############################################
+####################################################
class MSG::Host < MSG::RbHost
def getByName(name)
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;
}
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 */
// 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);
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);
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);
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