Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove unused include "simgrid_config.h"
[simgrid.git] / src / bindings / ruby / simgrid.rb
index eea2fa9..32fbbe2 100644 (file)
@@ -5,44 +5,11 @@
 # This program is free software; you can redistribute it and/or modify it
 #  under the terms of the license (GNU LGPL) which comes with this package. */
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
-require 'simgrid_ruby'
+require 'libsimgrid.so'
 require 'thread'
 
-##########################################################
-# Class Semaphore 
-##########################################################
-class MySemaphore
-   Thread.abort_on_exception = true
-    attr_accessor :permits
-
-  def initialize (permits = 0)
-       @permits = permits
-  end
-  
-  def acquire(mutex,cv)
-
-    raise "Interrupted Thread " if (!Thread.current.alive?)
-    mutex.synchronize {
-    while @permits <= 0
-       
-       cv.wait(mutex)
-       
-    end
-    @permits = @permits - 1
-    cv.signal
-    }
-    
-  end
-    
-  def release(mutex,cv)
-    mutex.synchronize{
-      @permits += 1
-      cv.signal
-      }
-  end  
-end
 #######################################
-# Another Semaphore
+#  Semaphore 
 #######################################
 
 class Semaphore
@@ -91,23 +58,20 @@ class MSG::Process < Thread
   @@nextProcessId = 0
 
 # Attributes
-  attr_reader :name, :pargs ,:properties, :cv, :mutex  # Read only
+  attr_reader :name, :pargs ,:properties       # Read only
   
     def initialize(*args)
       super(){
        
      raise "Bad number of arguments to create a Ruby process. Expected (name,args,prop) " if args.size < 3
      
-    @cv = ConditionVariable.new
-    @mutex = Mutex.new
-    @schedBegin = MySemaphore.new(0)
-    @schedEnd = MySemaphore.new(0)    
+    @schedBegin = Semaphore.new(0)
+    @schedEnd = Semaphore.new(0)    
     @id = @@nextProcessId
     @@nextProcessId +=1
     @name = args[0]
     @pargs = args[1]
     @properties = args[2]
-      
     start()
       }
     end
@@ -118,19 +82,13 @@ class MSG::Process < Thread
   end
      
   def start()
-     @schedBegin.acquire(@mutex,@cv)
-
+    @schedBegin.acquire
     MSG::debug("Let's execute the main() of the Ruby process")
     main(@pargs)
-<<<<<<< .mine
-#     processExit(self) # FIXME : Fix the simix_context_ruby_stop to stop context process before quitting
-    @schedEnd.release(@mutex,@cv)
-    
-=======
-    @schedEnd.release()
->>>>>>> .r7205
+    @schedEnd.release
     MSG::debug("Released my schedEnd, bailing out")
     processExit(self) # Exit the Native Process
+    
   end
     
   def getBind()
@@ -142,13 +100,13 @@ class MSG::Process < Thread
   end
     
   def unschedule()
-    @schedEnd.release(@mutex,@cv)
-    @schedBegin.acquire(@mutex,@cv)
+    @schedEnd.release
+    @schedBegin.acquire
   end
   
   def schedule()   
-    @schedBegin.release(@mutex,@cv)
-    @schedEnd.acquire(@mutex,@cv)
+    @schedBegin.release
+    @schedEnd.acquire
   end
   
   def pause()
@@ -166,32 +124,41 @@ class MSG::Process < Thread
   def getHost()
     processGetHost(self)
   end
-  
-# The Rest of Methods !!! To be Continued ... FIXME: what's missing?
-end
 
+end
 ############################################
 # Task Extend from the native Class RbTask
 ############################################
 class MSG::Task < MSG::RbTask
-
+  
   def initialize(*args)
-     super()
+    #Nothing todo   
+  end
+  
+  def join(value) 
+    super(self,value)
+  end
+  
+  def data()
+    super(self)
   end
   
   def name
-     super(self)
+   super(self)
   end
   
   def compSize
-     super(self)
+    super(self)
   end
   
   def send(mailbox)
-    super(self,mailbox)
+   super(self,mailbox)
+  end
+  
+  def receive(mailbox)
+    super(self)
   end
   
-
   def source
     super(self)
   end
@@ -201,7 +168,7 @@ class MSG::Task < MSG::RbTask
   end
   
   def listen(t_alias)
-    super(t_alias)
+    super(self)
   end
   
   def execute
@@ -209,15 +176,42 @@ class MSG::Task < MSG::RbTask
   end
     
   def listenFromHost(t_alias,host)
-    super(t_alias,host)
+    super(self)
   end
+  
+  def setPriority(priority)
+    super(self,priority)
+  end
+  
+  def cancel
+    super(self)
+  end
+  
+  def hasData
+    super(self)
+  end
+   
 end  
 
 ####################################################
 # Host Extend from the native Class RbHost
 ####################################################
 class MSG::Host < MSG::RbHost
-
+  
+  attr_reader :data
+  def initialize(*ars)
+    @data = 1
+    p "Host Initializer"
+  end
+  
+  def data()
+    return @data
+  end
+  
+  def setData(value)
+    @data = value
+  end
+  
   def getByName(name)
     super(name)
   end
@@ -234,10 +228,6 @@ class MSG::Host < MSG::RbHost
     super(self)
   end
   
-  def setData(data)
-    super(self,data)
-  end
-  
   def isAvail
     super(self)
   end
@@ -245,8 +235,12 @@ class MSG::Host < MSG::RbHost
   def number
     super()
   end
+  
+  def getHostProcess(process)
+    super(process)
+  end
+    
 end
-
 #########################
 # Main chunck 
 #########################