class WeakStore

Attributes

exit[RW]

Public Class Methods

new() click to toggle source
# File core/lib/weakstorage.rb, line 17
def initialize
  @_storage = gen_storage
  @_mutex = Monitor.new
  @_tls_name = "weakstore_lock_#{@_mutex.object_id}".to_sym
  @exit = false end

Public Instance Methods

atomic(&proc) click to toggle source
# File core/lib/weakstorage.rb, line 23
def atomic(&proc)
  if not exit
    Thread.current[@_tls_name] ||= 0
    Thread.current[@_tls_name] += 1
    begin
      @_mutex.synchronize(&proc)
    ensure
      Thread.current[@_tls_name] -= 1 end end end

Protected Instance Methods

storage() click to toggle source
# File core/lib/weakstorage.rb, line 34
def storage
  if(Thread.current[@_tls_name] and Thread.current[@_tls_name] >= 1)
    @_storage
  else
    raise "WeakStore inner storage can control in atomic{} block only. #{Thread.current[@_tls_name]}"
    nil end end