X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/91bec12b79ccabec119048b74d7e6f1814699dc5..6760cb07d6b57be16928d95339d71e57c4e24f36:/src/bindings/ruby/simgrid.rb diff --git a/src/bindings/ruby/simgrid.rb b/src/bindings/ruby/simgrid.rb index 3c5eedea18..32fbbe2814 100644 --- a/src/bindings/ruby/simgrid.rb +++ b/src/bindings/ruby/simgrid.rb @@ -1,13 +1,16 @@ -# FIXME: add license like in C files - -require 'simgrid_ruby' +# 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 'libsimgrid.so' require 'thread' -$DEBUG = false # This is a Global Variable Useful for MSG::debugging - -########################################################################### -# Class Semaphore -########################################################################### +####################################### +# Semaphore +####################################### class Semaphore def initialize(initvalue = 0) @@ -16,11 +19,13 @@ class Semaphore end def acquire - MSG::debug("Acquire "+self.to_s) Thread.critical = true if (@counter -= 1) < 0 + MSG::debug(Thread.current.to_s+" acquires "+self.to_s+". That's blocking.") @waiting_list.push(Thread.current) Thread.stop + else + MSG::debug(Thread.current.to_s+" acquires "+self.to_s+". It was free.") end self ensure @@ -28,15 +33,14 @@ class Semaphore end def release - MSG::debug("Release "+self.to_s) Thread.critical = true begin if (@counter += 1) <= 0 t = @waiting_list.shift t.wakeup if t - MSG::debug("Wakeup "+t.to_s) + MSG::debug(Thread.current.to_s+" releases "+self.to_s+". Wakeup "+t.to_s) else - MSG::debug("Nobody to wakeup") + MSG::debug(Thread.current.to_s+" releases "+self.to_s+". Nobody to wakeup") end rescue ThreadError retry @@ -54,17 +58,17 @@ class MSG::Process < Thread @@nextProcessId = 0 # Attributes - attr_reader :bind, :id, :name, :pargs ,:properties# Read only + attr_reader :name, :pargs ,:properties # Read only def initialize(*args) super(){ - raise "Bad Number Of arguments to create a Ruby Process (name,args,prop) " if args.size < 3 + raise "Bad number of arguments to create a Ruby process. Expected (name,args,prop) " if args.size < 3 @schedBegin = Semaphore.new(0) @schedEnd = Semaphore.new(0) - #@properties = Hash.new() FIXME: get this from the C (yep that makes 4 args to this function) - @id = @@nextProcessId++ + @id = @@nextProcessId + @@nextProcessId +=1 @name = args[0] @pargs = args[1] @properties = args[2] @@ -72,30 +76,25 @@ class MSG::Process < Thread } end - # main def main(args) # To be overriden by childs raise("You must define a main() function in your process, containing the code of this process") end - # Start : To keep the process alive and waiting via semaphore def start() @schedBegin.acquire - # execute the main code of the process - MSG::debug("Begin execution") + MSG::debug("Let's execute the main() of the Ruby process") main(@pargs) -# processExit(self) # Exit the Native Process @schedEnd.release + MSG::debug("Released my schedEnd, bailing out") + processExit(self) # Exit the Native Process + end - - - # Get Bind def getBind() return @bind end - - # Set Binds + def setBind(bind) @bind = bind end @@ -105,7 +104,7 @@ class MSG::Process < Thread @schedBegin.acquire end - def schedule() + def schedule() @schedBegin.release @schedEnd.acquire end @@ -125,33 +124,39 @@ class MSG::Process < Thread def getHost() processGetHost(self) end - -# The Rest of Methods !!! To be Continued ... FIXME: what's missing? -end +end ############################################ # Task Extend from the native Class RbTask ############################################ class MSG::Task < MSG::RbTask - + def initialize(*args) - super() + #Nothing todo + end + + def join(value) + super(self,value) + end + + def data() + super(self) end def name - super(self) + super(self) end def compSize - super(self) + super(self) end def send(mailbox) - super(mailbox) + super(self,mailbox) end def receive(mailbox) - super(mailbox) + super(self) end def source @@ -163,7 +168,7 @@ class MSG::Task < MSG::RbTask end def listen(t_alias) - super(t_alias) + super(self) end def execute @@ -171,16 +176,42 @@ class MSG::Task < MSG::RbTask end def listenFromHost(t_alias,host) - super(t_alias,host) + super(self) end - + + def setPriority(priority) + super(self,priority) + end + + def cancel + super(self) + end + + def hasData + super(self) + end + end -############################################ +#################################################### # Host Extend from the native Class RbHost -############################################ +#################################################### class MSG::Host < MSG::RbHost - + + attr_reader :data + def initialize(*ars) + @data = 1 + p "Host Initializer" + end + + def data() + return @data + end + + def setData(value) + @data = value + end + def getByName(name) super(name) end @@ -197,10 +228,6 @@ class MSG::Host < MSG::RbHost super(self) end - def setData(data) - super(self,data) - end - def isAvail super(self) end @@ -209,8 +236,11 @@ class MSG::Host < MSG::RbHost super() end + def getHostProcess(process) + super(process) + end + end - ######################### # Main chunck #########################