1 # FIXME: add license like in C files
6 $DEBUG = false # This is a Global Variable Useful for MSG::debugging
8 ###########################################################################
10 ###########################################################################
12 Thread.abort_on_exception = true
13 attr_accessor :permits
16 def initialize (permits = 0)
22 raise "Interrupted Thread " if (!Thread.current.alive?)
29 @permits = @permits - 1
42 #######################################
44 #######################################
47 def initialize(initvalue = 0)
53 MSG::debug(Thread.current.to_s+" acquires "+self.to_s)
54 Thread.critical = true
55 if (@counter -= 1) < 0
56 @waiting_list.push(Thread.current)
61 Thread.critical = false
65 MSG::debug(Thread.current.to_s+" releases "+self.to_s)
66 Thread.critical = true
68 if (@counter += 1) <= 0
69 t = @waiting_list.shift
71 MSG::debug("Wakeup "+t.to_s)
73 MSG::debug("Nobody to wakeup")
80 Thread.critical = false
84 ########################################################################
86 ########################################################################
87 class MSG::Process < Thread
91 attr_reader :bind, :id, :name, :pargs ,:properties# Read only
96 raise "Bad Number Of arguments to create a Ruby Process (name,args,prop) " if args.size < 3
98 # @cv = ConditionVariable.new
100 @schedBegin = Semaphore.new(0)
101 @schedEnd = Semaphore.new(0)
102 @id = @@nextProcessId
106 @properties = args[2]
114 # To be overriden by childs
115 raise("You must define a main() function in your process, containing the code of this process")
118 # Start : To keep the process alive and waiting via semaphore
120 @schedBegin.acquire()
121 # execute the main code of the process
122 MSG::debug("Begin execution")
124 # processExit(self) # Exit the Native Process
129 # FIXME: useless, there is an attribute for bind (or the attribute is useless)
135 # Set Binds FIXME: same
142 @schedBegin.acquire()
146 @schedBegin.release()
159 processIsSuspended(self)
166 # The Rest of Methods !!! To be Continued ... FIXME: what's missing?
169 ############################################
170 # Task Extend from the native Class RbTask
171 ############################################
172 class MSG::Task < MSG::RbTask
174 def initialize(*args)
190 # FIXME : this methode should be associated to the class !! it reurn a task
211 def listenFromHost(t_alias,host)
217 ############################################
218 # Host Extend from the native Class RbHost
219 ############################################
220 class MSG::Host < MSG::RbHost
252 #########################
254 #########################