Class: ACE::FileMutex
- Inherits:
-
Object
- Object
- ACE::FileMutex
- Defined in:
- lib/ace/file_mutex.rb
Instance Method Summary collapse
-
#initialize(lock_file) ⇒ FileMutex
constructor
A new instance of FileMutex.
- #with_read_lock ⇒ Object
- #with_write_lock ⇒ Object
Constructor Details
#initialize(lock_file) ⇒ FileMutex
Returns a new instance of FileMutex.
7 8 9 |
# File 'lib/ace/file_mutex.rb', line 7 def initialize(lock_file) @lock_file = lock_file end |
Instance Method Details
#with_read_lock ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/ace/file_mutex.rb', line 11 def with_read_lock fh = File.open(@lock_file, File::CREAT) fh.flock(File::LOCK_SH) yield ensure fh.flock(File::LOCK_UN) fh.close end |
#with_write_lock ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/ace/file_mutex.rb', line 20 def with_write_lock fh = File.open(@lock_file, File::CREAT) fh.flock(File::LOCK_EX) yield ensure fh.flock(File::LOCK_UN) fh.close end |