instance method
yield_shares
Ruby on Rails edge
Since v5.0.7.2Signature
yield_shares(purpose: nil, compatible: [], block_share: false)
Temporarily give up all held Share locks while executing the supplied block, allowing any compatible exclusive lock request to proceed.
Parameters
-
purposekey = nil -
compatiblekey = [] -
block_sharekey = false
Source
# File activesupport/lib/active_support/concurrency/share_lock.rb, line 175
def yield_shares(purpose: nil, compatible: [], block_share: false)
loose_shares = previous_wait = nil
owner = current_owner
synchronize do
if loose_shares = @sharing.delete(owner)
if previous_wait = @waiting[owner]
purpose = nil unless purpose == previous_wait[0]
compatible &= previous_wait[1]
end
compatible |= [false] unless block_share
@waiting[owner] = [purpose, compatible]
end
@cv.broadcast
end
begin
yield
ensure
synchronize do
wait_for(:yield_shares) { @exclusive_owner && @exclusive_owner != owner }
if previous_wait
@waiting[owner] = previous_wait
else
@waiting.delete owner
end
@sharing[owner] = loose_shares if loose_shares
end
end
end
Defined in activesupport/lib/active_support/concurrency/share_lock.rb line 175
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Concurrency::ShareLock