1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
module Concurrent
module Synchronization
class Condition < LockableObject
safe_initialization!
# TODO (pitr 12-Sep-2015): locks two objects, improve
singleton_class.send :alias_method, :private_new, :new
private_class_method :new
def initialize(lock)
super()
@Lock = lock
end
def wait(timeout = nil)
@Lock.synchronize { ns_wait(timeout) }
end
def ns_wait(timeout = nil)
synchronize { super(timeout) }
end
def wait_until(timeout = nil, &condition)
@Lock.synchronize { ns_wait_until(timeout, &condition) }
end
def ns_wait_until(timeout = nil, &condition)
synchronize { super(timeout, &condition) }
end
def signal
@Lock.synchronize { ns_signal }
end
def ns_signal
synchronize { super }
end
def broadcast
@Lock.synchronize { ns_broadcast }
end
def ns_broadcast
synchronize { super }
end
end
class LockableObject < LockableObjectImplementation
def new_condition
Condition.private_new(self)
end
end
end
end
|