Class: DaemonController::LockFile
- Inherits:
-
Object
- Object
- DaemonController::LockFile
- Defined in:
- lib/daemon_controller/lock_file.rb
Instance Method Summary collapse
- #exclusive_lock ⇒ Object
-
#initialize(filename) ⇒ LockFile
constructor
A new instance of LockFile.
- #shared_lock ⇒ Object
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_lock ⇒ Object
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_lock ⇒ Object
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 |