Module: ActiveRecord::ConnectionAdapters::ConnectionPool::BiasableQueue

Included in:
ConnectionLeasingQueue
Defined in:
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb

Overview

Adds the ability to turn a basic fair FIFO queue into one biased to some thread.

Defined Under Namespace

Classes: BiasedConditionVariable

Instance Method Summary collapse

Instance Method Details

#with_a_bias_for(thread) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb', line 273

def with_a_bias_for(thread)
  previous_cond = nil
  new_cond      = nil
  synchronize do
    previous_cond = @cond
    @cond = new_cond = BiasedConditionVariable.new(@lock, @cond, thread)
  end
  yield
ensure
  synchronize do
    @cond = previous_cond if previous_cond
    new_cond.broadcast_on_biased if new_cond # wake up any remaining sleepers
  end
end