Class: FiberedMysql2::FiberedConditionVariable
- Inherits:
-
Object
- Object
- FiberedMysql2::FiberedConditionVariable
- Defined in:
- lib/fibered_mysql2/fibered_database_connection_pool.rb
Defined Under Namespace
Classes: Timeout
Constant Summary collapse
- EXCEPTION_NEVER =
{Exception => :never}.freeze
- EXCEPTION_IMMEDIATE =
{Exception => :immediate}.freeze
Instance Method Summary collapse
-
#broadcast ⇒ Object
Wakes up all threads waiting for this lock.
-
#initialize(monitor) ⇒ FiberedConditionVariable
constructor
A new instance of FiberedConditionVariable.
-
#signal ⇒ Object
Wakes up the first thread in line waiting for this lock.
-
#wait(timeout = nil) ⇒ Object
Releases the lock held in the associated monitor and waits; reacquires the lock on wakeup.
-
#wait_until ⇒ Object
Calls wait repeatedly until the given block yields a truthy value.
-
#wait_while ⇒ Object
Calls wait repeatedly while the given block yields a truthy value.
Constructor Details
#initialize(monitor) ⇒ FiberedConditionVariable
Returns a new instance of FiberedConditionVariable.
82 83 84 85 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 82 def initialize(monitor) @monitor = monitor @cond = EM::Synchrony::Thread::ConditionVariable.new end |
Instance Method Details
#broadcast ⇒ Object
Wakes up all threads waiting for this lock.
77 78 79 80 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 77 def broadcast @monitor.__send__(:mon_check_owner) @cond.broadcast end |
#signal ⇒ Object
Wakes up the first thread in line waiting for this lock.
69 70 71 72 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 69 def signal @monitor.__send__(:mon_check_owner) @cond.signal end |
#wait(timeout = nil) ⇒ Object
Releases the lock held in the associated monitor and waits; reacquires the lock on wakeup.
If timeout
is given, this method returns after timeout
seconds passed, even if no other thread doesn’t signal.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 33 def wait(timeout = nil) Thread.handle_interrupt(EXCEPTION_NEVER) do @monitor.__send__(:mon_check_owner) count = @monitor.__send__(:mon_exit_for_cond) begin Thread.handle_interrupt(EXCEPTION_IMMEDIATE) do @cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout) end return true ensure @monitor.__send__(:mon_enter_for_cond, count) end end end |
#wait_until ⇒ Object
Calls wait repeatedly until the given block yields a truthy value.
60 61 62 63 64 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 60 def wait_until until yield wait end end |
#wait_while ⇒ Object
Calls wait repeatedly while the given block yields a truthy value.
51 52 53 54 55 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 51 def wait_while while yield wait end end |