Class: QuackConcurrency::Waiter Private
- Inherits:
-
Object
- Object
- QuackConcurrency::Waiter
- Defined in:
- lib/quack_concurrency/waiter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Waiter is similar to ConditionVariable.
A few differences include:
Instance Method Summary collapse
-
#any_waiting_threads? ⇒ Boolean
private
Checks if any threads are waiting on it.
-
#initialize ⇒ Waiter
constructor
private
Creates a new Waiter concurrency tool.
-
#resume_all ⇒ void
private
Resumes all threads waiting on it.
-
#resume_all_indefinitely ⇒ void
private
Resumes all threads waiting on it and will cause any future calls to #wait to return immediately.
-
#resume_next ⇒ void
private
Resumes next thread waiting on it if one exists.
-
#wait ⇒ void
private
Puts this thread to sleep until another thread resumes it via this Waiter.
-
#waiting_threads_count ⇒ Integer
private
Returns the number of threads waiting on it.
Constructor Details
#initialize ⇒ Waiter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new QuackConcurrency::Waiter concurrency tool.
16 17 18 19 20 |
# File 'lib/quack_concurrency/waiter.rb', line 16 def initialize @condition_variable = SafeConditionVariable.new @resume_all_indefinitely = false @mutex = ::Mutex.new end |
Instance Method Details
#any_waiting_threads? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if any threads are waiting on it.
24 25 26 |
# File 'lib/quack_concurrency/waiter.rb', line 24 def any_waiting_threads? @condition_variable.any_waiting_threads? end |
#resume_all ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Resumes all threads waiting on it.
30 31 32 |
# File 'lib/quack_concurrency/waiter.rb', line 30 def resume_all @condition_variable.broadcast end |
#resume_all_indefinitely ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Resumes all threads waiting on it and will cause
any future calls to {#wait} to return immediately.
37 38 39 40 41 42 |
# File 'lib/quack_concurrency/waiter.rb', line 37 def resume_all_indefinitely @mutex.synchronize do @resume_all_indefinitely = true resume_all end end |
#resume_next ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Resumes next thread waiting on it if one exists.
46 47 48 |
# File 'lib/quack_concurrency/waiter.rb', line 46 def resume_next @condition_variable.signal end |
#wait ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Will block until resumed.
This method returns an undefined value.
Puts this thread to sleep until another thread resumes it via this QuackConcurrency::Waiter.
53 54 55 56 57 58 |
# File 'lib/quack_concurrency/waiter.rb', line 53 def wait @mutex.synchronize do return if @resume_all_indefinitely @condition_variable.wait(@mutex) end end |
#waiting_threads_count ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the number of threads waiting on it.
62 63 64 |
# File 'lib/quack_concurrency/waiter.rb', line 62 def waiting_threads_count @condition_variable.waiting_threads_count end |