1 # FIXME: add license like in C files
6 ###########################################################################
8 ###########################################################################
10 Thread.abort_on_exception = true
11 attr_accessor :permits
14 def initialize (permits = 0)
20 raise "Interrupted Thread " if (!Thread.current.alive?)
27 @permits = @permits - 1
40 #######################################
42 #######################################
45 def initialize(initvalue = 0)
51 Thread.critical = true
52 if (@counter -= 1) < 0
53 MSG::debug(Thread.current.to_s+" acquires "+self.to_s+". That's blocking.")
54 @waiting_list.push(Thread.current)
57 MSG::debug(Thread.current.to_s+" acquires "+self.to_s+". It was free.")
61 Thread.critical = false
65 Thread.critical = true
67 if (@counter += 1) <= 0
68 t = @waiting_list.shift
70 MSG::debug(Thread.current.to_s+" releases "+self.to_s+". Wakeup "+t.to_s)
72 MSG::debug(Thread.current.to_s+" releases "+self.to_s+". Nobody to wakeup")
79 Thread.critical = false
83 ########################################################################
85 ########################################################################
86 class MSG::Process < Thread
90 attr_reader :bind, :id, :name, :pargs ,:properties# Read only
95 raise "Bad number of arguments to create a Ruby process. Expected (name,args,prop) " if args.size < 3
97 # @cv = ConditionVariable.new
99 @schedBegin = Semaphore.new(0)
100 @schedEnd = Semaphore.new(0)
101 @id = @@nextProcessId
105 @properties = args[2]
112 # To be overriden by childs
113 raise("You must define a main() function in your process, containing the code of this process")
117 @schedBegin.acquire()
118 MSG::debug("Let's execute the main() of the Ruby process")
120 # processExit(self) # Exit the Native Process
125 # FIXME: useless, there is an attribute for bind (or the attribute is useless)
131 # Set Binds FIXME: same
138 @schedBegin.acquire()
142 @schedBegin.release()
155 processIsSuspended(self)
162 # The Rest of Methods !!! To be Continued ... FIXME: what's missing?
165 ############################################
166 # Task Extend from the native Class RbTask
167 ############################################
168 class MSG::Task < MSG::RbTask
170 def initialize(*args)
186 # FIXME : this method should be associated to the class !! it return a task
187 # FIXME: simply killing this adapter method should do the trick
208 def listenFromHost(t_alias,host)
213 ############################################
214 # Host Extend from the native Class RbHost
215 ############################################
216 class MSG::Host < MSG::RbHost
247 #########################
249 #########################