class Concurrent::Transaction

@!visibility private

def self.current

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

def self.current=(transaction)

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

def abort

def abort
  unlock
end

def commit

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

def initialize

def initialize
  @open_tvars = {}
end

def open(tvar)

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

def read(tvar)

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

def unlock

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

def write(tvar, value)

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