X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/18e8a1c4541f992e82b48f3d17202ba6fd5386a0..7bcd4cc9d936caa1d23579f7aca67e68fade2a36:/src/bindings/ruby/simgrid.rb diff --git a/src/bindings/ruby/simgrid.rb b/src/bindings/ruby/simgrid.rb index 9bd954bc86..c618f33a61 100644 --- a/src/bindings/ruby/simgrid.rb +++ b/src/bindings/ruby/simgrid.rb @@ -1,44 +1,15 @@ -# 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 - - 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 - } - - end - - def release(mutex,cv) - mutex.synchronize{ - @permits += 1 - cv.signal - } - end -end ####################################### -# Another Semaphore +# Semaphore ####################################### class Semaphore @@ -87,15 +58,13 @@ 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. Expected (name,args,prop) " if args.size < 3 -# @cv = ConditionVariable.new -# @mutex = Mutex.new @schedBegin = Semaphore.new(0) @schedEnd = Semaphore.new(0) @id = @@nextProcessId @@ -103,7 +72,6 @@ class MSG::Process < Thread @name = args[0] @pargs = args[1] @properties = args[2] - start() } end @@ -114,33 +82,31 @@ class MSG::Process < Thread end def start() - @schedBegin.acquire() + @schedBegin.acquire MSG::debug("Let's execute the main() of the Ruby process") main(@pargs) -# processExit(self) # Exit the Native Process - @schedEnd.release() + @schedEnd.release + 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 + @schedBegin.acquire end - def schedule() - @schedBegin.release() - @schedEnd.acquire() + def schedule() + @schedBegin.release + @schedEnd.acquire end def pause() @@ -158,17 +124,24 @@ class MSG::Process < Thread def getHost() processGetHost(self) end - + # The Rest of Methods !!! To be Continued ... FIXME: what's missing? end - ############################################ # Task Extend from the native Class RbTask ############################################ class MSG::Task < MSG::RbTask def initialize(*args) - super() + super() + end + + def setData(value) + super(self,value) + end + + def data() + super(self) end def name @@ -183,12 +156,6 @@ 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 @@ -208,13 +175,20 @@ class MSG::Task < MSG::RbTask def listenFromHost(t_alias,host) super(t_alias,host) end + + def setPriority(priority) + super(self,priority) + end + + def cancel() + super(self) + end + end - -############################################ +#################################################### # Host Extend from the native Class RbHost -############################################ +#################################################### class MSG::Host < MSG::RbHost - def getByName(name) super(name) end @@ -242,9 +216,13 @@ class MSG::Host < MSG::RbHost def number super() end + + def getHostProcess(process) + super(process) + end + end - ######################### # Main chunck ######################### -MSG.init(ARGV) +MSG.init(ARGV) \ No newline at end of file