Class: DaemonController::LockFile

Inherits:
Object
  • Object
show all
Defined in:
lib/daemon_controller/lock_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ LockFile

Returns a new instance of LockFile.



24
25
26
# File 'lib/daemon_controller/lock_file.rb', line 24

def initialize(filename)
	@filename = filename
end

Instance Method Details

#exclusive_lockObject



28
29
30
31
32
33
34
35
36
# File 'lib/daemon_controller/lock_file.rb', line 28

def exclusive_lock
	File.open(@filename, 'w') do |f|
		if Fcntl.const_defined? :F_SETFD
			f.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
		end
		f.flock(File::LOCK_EX)
		yield
	end
end

#shared_lockObject



38
39
40
41
42
43
44
45
46
# File 'lib/daemon_controller/lock_file.rb', line 38

def shared_lock
	File.open(@filename, 'w') do |f|
		if Fcntl.const_defined? :F_SETFD
			f.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
		end
		f.flock(File::LOCK_SH)
		yield
	end
end