1 # Task-related bindings to ruby */
3 # Copyright 2010. The SimGrid Team. All right reserved. */
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the license (GNU LGPL) which comes with this package. */
7 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
11 #######################################
13 #######################################
16 def initialize(initvalue = 0)
22 Thread.critical = true
23 if (@counter -= 1) < 0
24 MSG::debug(Thread.current.to_s+" acquires "+self.to_s+". That's blocking.")
25 @waiting_list.push(Thread.current)
28 MSG::debug(Thread.current.to_s+" acquires "+self.to_s+". It was free.")
32 Thread.critical = false
36 Thread.critical = true
38 if (@counter += 1) <= 0
39 t = @waiting_list.shift
41 MSG::debug(Thread.current.to_s+" releases "+self.to_s+". Wakeup "+t.to_s)
43 MSG::debug(Thread.current.to_s+" releases "+self.to_s+". Nobody to wakeup")
50 Thread.critical = false
54 ########################################################################
56 ########################################################################
57 class MSG::Process < Thread
61 attr_reader :name, :pargs ,:properties # Read only
66 raise "Bad number of arguments to create a Ruby process. Expected (name,args,prop) " if args.size < 3
68 @schedBegin = Semaphore.new(0)
69 @schedEnd = Semaphore.new(0)
81 # To be overriden by childs
82 raise("You must define a main() function in your process, containing the code of this process")
87 MSG::debug("Let's execute the main() of the Ruby process")
90 MSG::debug("Released my schedEnd, bailing out")
91 processExit(self) # Exit the Native Process
122 processIsSuspended(self)
129 # The Rest of Methods !!! To be Continued ... FIXME: what's missing?
131 ############################################
132 # Task Extend from the native Class RbTask
133 ############################################
134 class MSG::Task < MSG::RbTask
136 def initialize(*args)
168 def listenFromHost(t_alias,host)
172 ####################################################
173 # Host Extend from the native Class RbHost
174 ####################################################
175 class MSG::Host < MSG::RbHost
204 #########################
206 #########################