Parent

Files

Class/Module Index [+]

Quicksearch

Moneta::SynchronizePrimitive

Base class for {Mutex} and {Semaphore} @api private

Public Instance Methods

enter(timeout = nil, wait = 0.01) click to toggle source

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
Also aliased as: lock
leave() click to toggle source

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
Also aliased as: unlock
lock(timeout = nil, wait = 0.01) click to toggle source
Alias for: enter
locked?() click to toggle source

Is the lock acquired?

@api public

# File lib/moneta/synchronize.rb, line 58
def locked?
  @locked
end
synchronize() click to toggle source

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_enter() click to toggle source

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
Also aliased as: try_lock
try_lock() click to toggle source
Alias for: try_enter
unlock() click to toggle source
Alias for: leave

[Validate]

Generated with the Darkfish Rdoc Generator 2.