123456789_123456789_123456789_123456789_123456789_

Class: Concurrent::Transaction

Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: lib/concurrent-ruby/concurrent/tvar.rb

Constant Summary

Class Attribute Summary

Class Method Summary

Instance Method Summary

Constructor Details

.newTransaction

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/tvar.rb', line 162

def initialize
  @open_tvars = {}
end

Class Attribute Details

.current (rw)

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/tvar.rb', line 212

def self.current
  Thread.current[:current_tvar_transaction]
end

.current=(transaction) (rw)

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/tvar.rb', line 216

def self.current=(transaction)
  Thread.current[:current_tvar_transaction] = transaction
end

Instance Method Details

#abort

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/tvar.rb', line 192

def abort
  unlock
end

#commit

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/tvar.rb', line 196

def commit
  @open_tvars.each do |tvar, entry|
    if entry.modified
      tvar.unsafe_value = entry.value
    end
  end

  unlock
end

#open(tvar)

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/tvar.rb', line 177

def open(tvar)
  entry = @open_tvars[tvar]

  unless entry
    unless tvar.unsafe_lock.try_lock
      Concurrent::abort_transaction
    end

    entry = OpenEntry.new(tvar.unsafe_value, false)
    @open_tvars[tvar] = entry
  end

  entry
end

#read(tvar)

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/tvar.rb', line 166

def read(tvar)
  entry = open(tvar)
  entry.value
end

#unlock

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/tvar.rb', line 206

def unlock
  @open_tvars.each_key do |tvar|
    tvar.unsafe_lock.unlock
  end
end

#write(tvar, value)

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/tvar.rb', line 171

def write(tvar, value)
  entry = open(tvar)
  entry.modified = true
  entry.value = value
end