class Dapp::Dimg::Lock::File

Attributes

counter[W]
locks_path[R]

Public Class Methods

counter() click to toggle source
# File lib/dapp/dimg/lock/file.rb, line 8
def counter
  @counter ||= 0
end
new(locks_path, name) click to toggle source
Calls superclass method Dapp::Dimg::Lock::Base::new
# File lib/dapp/dimg/lock/file.rb, line 15
def initialize(locks_path, name)
  super(name)

  @locks_path = Pathname.new(locks_path).tap(&:mkpath)
end

Protected Instance Methods

_do_lock(timeout, on_wait, readonly) click to toggle source
# File lib/dapp/dimg/lock/file.rb, line 27
def _do_lock(timeout, on_wait, readonly)
  @file = ::File.open(lock_file_path, ::File::RDWR | ::File::CREAT, 0o644)

  begin
    mode = (readonly ? ::File::LOCK_SH : ::File::LOCK_EX)
    _waiting(timeout, on_wait) { @file.flock(mode) } unless @file.flock(mode | ::File::LOCK_NB)
  rescue ::Timeout::Error
    raise ::Dapp::Dimg::Error::Lock, code: :timeout, data: { name: name, timeout: timeout }
  end

  self.class.counter += 1
end
_do_unlock() click to toggle source
# File lib/dapp/dimg/lock/file.rb, line 40
def _do_unlock
  @file.close
  @file = nil
  self.class.counter -= 1
end
lock_file_path() click to toggle source
# File lib/dapp/dimg/lock/file.rb, line 23
def lock_file_path
  locks_path.join(MurmurHash3::V32.str_hexdigest(name))
end