Object
Base class for {Mutex} and {Semaphore} @api private
Enter critical section (blocking)
@api public @param [Number] timeout Maximum time to wait @param [Number] wait Sleep time between tries to acquire lock @return [Boolean] true if the lock was aquired
# File lib/moneta/synchronize.rb, line 33 def enter(timeout = nil, wait = 0.01) total = 0 while !timeout || total < timeout return true if try_enter sleep(wait) total += wait end false end
Leave critical section
@api public
# File lib/moneta/synchronize.rb, line 47 def leave raise 'Not locked' unless @locked leave_primitive @locked = false nil end
Is the lock acquired?
@api public
# File lib/moneta/synchronize.rb, line 58 def locked? @locked end
Synchronize block
@api public @yieldparam Synchronized block @return [Object] result of block
# File lib/moneta/synchronize.rb, line 10 def synchronize enter yield ensure leave end
Try to enter critical section (nonblocking)
@api public @return [Boolean] true if the lock was acquired
# File lib/moneta/synchronize.rb, line 21 def try_enter raise 'Already locked' if @locked enter_primitive ? @locked = true : false end
Generated with the Darkfish Rdoc Generator 2.