Files

Class/Module Index [+]

Quicksearch

Concurrent::Synchronization::RbxObject

@!visibility private @!macro internal_implementation_note

Public Class Methods

new() click to toggle source
# File lib/concurrent/synchronization/rbx_object.rb, line 9
def initialize
  @Waiters = []
  ensure_ivar_visibility!
end

Protected Class Methods

attr_volatile(*names) click to toggle source
# File lib/concurrent/synchronization/rbx_object.rb, line 55
def self.attr_volatile *names
  names.each do |name|
    ivar = :"@volatile_#{name}"
    class_eval             def #{name}              Rubinius.memory_barrier              #{ivar}            end            def #{name}=(value)              #{ivar} = value              Rubinius.memory_barrier            end, __FILE__, __LINE__ + 1
  end
  names.map { |n| [n, :"#{n}="] }.flatten
end

Protected Instance Methods

ensure_ivar_visibility!() click to toggle source
# File lib/concurrent/synchronization/rbx_object.rb, line 50
def ensure_ivar_visibility!
  # Rubinius instance variables are not volatile so we need to insert barrier
  Rubinius.memory_barrier
end
ns_broadcast() click to toggle source
# File lib/concurrent/synchronization/rbx_object.rb, line 45
def ns_broadcast
  @Waiters.shift << true until @Waiters.empty?
  self
end
ns_signal() click to toggle source
# File lib/concurrent/synchronization/rbx_object.rb, line 40
def ns_signal
  @Waiters.shift << true unless @Waiters.empty?
  self
end
ns_wait(timeout = nil) click to toggle source
# File lib/concurrent/synchronization/rbx_object.rb, line 20
def ns_wait(timeout = nil)
  wchan = Rubinius::Channel.new

  begin
    @Waiters.push wchan
    Rubinius.unlock(self)
    signaled = wchan.receive_timeout timeout
  ensure
    Rubinius.lock(self)

    if !signaled && !@Waiters.delete(wchan)
      # we timed out, but got signaled afterwards,
      # so pass that signal on to the next waiter
      @Waiters.shift << true unless @Waiters.empty?
    end
  end

  self
end
synchronize(&block) click to toggle source
# File lib/concurrent/synchronization/rbx_object.rb, line 16
def synchronize(&block)
  Rubinius.synchronize(self, &block)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.