1 # FIXME: add license like in C files
6 $DEBUG = false # This is a Global Variable Useful for MSG::debugging
8 ###########################################################################
10 ###########################################################################
13 def initialize(initvalue = 0)
19 MSG::debug("Acquire "+self.to_s)
20 Thread.critical = true
21 if (@counter -= 1) < 0
22 @waiting_list.push(Thread.current)
27 Thread.critical = false
31 MSG::debug("Release "+self.to_s)
32 Thread.critical = true
34 if (@counter += 1) <= 0
35 t = @waiting_list.shift
37 MSG::debug("Wakeup "+t.to_s)
39 MSG::debug("Nobody to wakeup")
46 Thread.critical = false
50 ########################################################################
52 ########################################################################
53 class MSG::Process < Thread
57 attr_reader :bind, :id, :name, :pargs # Read only
58 attr_accessor :properties # R/W
64 raise "Bad Number Of arguments to create a a Ruby Process (name,args,prop) " if args.size < 3
66 @schedBegin = Semaphore.new(0)
67 @schedEnd = Semaphore.new(0)
68 #@properties = Hash.new() FIXME: get this from the C (yep that makes 4 args to this function)
69 @id = @@nextProcessId++
83 # To be overriden by childs
84 raise("You must define a main() function in your process, containing the code of this process")
87 # Start : To keep the process alive and waiting via semaphore
90 # execute the main code of the process
91 MSG::debug("Begin execution")
93 processExit(self) # Exit the Native Process
128 processIsSuspended(self)
135 # The Rest of Methods !!! To be Continued ... FIXME: what's missing?
138 #########################
140 #########################