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)
80 # To be overriden by childs
81 raise("You must define a main() function in your process, containing the code of this process")
86 MSG::debug("Let's execute the main() of the Ruby process")
89 MSG::debug("Released my schedEnd, bailing out")
90 processExit(self) # Exit the Native Process
121 processIsSuspended(self)
129 ############################################
130 # Task Extend from the native Class RbTask
131 ############################################
132 class MSG::Task < MSG::RbTask
134 def initialize(*args)
178 def listenFromHost(t_alias,host)
182 def setPriority(priority)
196 ####################################################
197 # Host Extend from the native Class RbHost
198 ####################################################
199 class MSG::Host < MSG::RbHost
239 def getHostProcess(process)
244 #########################
246 #########################