Class: ActiveRecord::ConnectionAdapters::ConnectionPool::BiasableQueue::BiasedConditionVariable
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::ConnectionPool::BiasableQueue::BiasedConditionVariable
- Defined in:
- activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb
Overview
:nodoc:
Instance Method Summary collapse
- #broadcast ⇒ Object
- #broadcast_on_biased ⇒ Object
-
#initialize(lock, other_cond, preferred_thread) ⇒ BiasedConditionVariable
constructor
semantics of condition variables guarantee that
broadcast
,broadcast_on_biased
,signal
andwait
methods are only called while holding a lock. - #signal ⇒ Object
- #wait(timeout) ⇒ Object
Constructor Details
#initialize(lock, other_cond, preferred_thread) ⇒ BiasedConditionVariable
semantics of condition variables guarantee that broadcast
, broadcast_on_biased
, signal
and wait
methods are only called while holding a lock
140 141 142 143 144 145 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb', line 140 def initialize(lock, other_cond, preferred_thread) @real_cond = lock.new_cond @other_cond = other_cond @preferred_thread = preferred_thread @num_waiting_on_real_cond = 0 end |
Instance Method Details
#broadcast ⇒ Object
147 148 149 150 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb', line 147 def broadcast broadcast_on_biased @other_cond.broadcast end |
#broadcast_on_biased ⇒ Object
152 153 154 155 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb', line 152 def broadcast_on_biased @num_waiting_on_real_cond = 0 @real_cond.broadcast end |
#signal ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb', line 157 def signal if @num_waiting_on_real_cond > 0 @num_waiting_on_real_cond -= 1 @real_cond else @other_cond end.signal end |
#wait(timeout) ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb', line 166 def wait(timeout) if Thread.current == @preferred_thread @num_waiting_on_real_cond += 1 @real_cond else @other_cond end.wait(timeout) end |