Class: Daybreak::Queue Private
- Inherits:
-
Object
- Object
- Daybreak::Queue
- Defined in:
- lib/daybreak/queue/mri.rb,
lib/daybreak/queue/threaded.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.
A queue for threaded implementations of ruby without a GIL
Direct Known Subclasses
Instance Method Summary collapse
- #<<(x) ⇒ Object private
- #close ⇒ Object private
- #first ⇒ Object private
- #flush ⇒ Object private
-
#initialize ⇒ Queue
constructor
private
A new instance of Queue.
- #pop ⇒ Object private
Constructor Details
#initialize ⇒ Queue
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 a new instance of Queue.
10 11 12 13 14 15 |
# File 'lib/daybreak/queue/mri.rb', line 10 def initialize @queue, @full, @empty = [], [], [] @stop = false @heartbeat = Thread.new(&method(:heartbeat)) @heartbeat.priority = -9 end |
Instance Method Details
#<<(x) ⇒ Object
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.
17 18 19 20 21 |
# File 'lib/daybreak/queue/mri.rb', line 17 def <<(x) @queue << x thread = @full.first thread.wakeup if thread end |
#close ⇒ Object
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.
56 57 58 59 |
# File 'lib/daybreak/queue/mri.rb', line 56 def close @stop = true @heartbeat.join end |
#first ⇒ Object
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.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/daybreak/queue/mri.rb', line 31 def first while @queue.empty? begin @full << Thread.current # If a push happens before Thread.stop, the thread won't be woken up Thread.stop while @queue.empty? ensure @full.delete(Thread.current) end end @queue.first end |
#flush ⇒ Object
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.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/daybreak/queue/mri.rb', line 44 def flush until @queue.empty? begin @empty << Thread.current # If a pop happens before Thread.stop, the thread won't be woken up Thread.stop until @queue.empty? ensure @empty.delete(Thread.current) end end end |
#pop ⇒ Object
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.
23 24 25 26 27 28 29 |
# File 'lib/daybreak/queue/mri.rb', line 23 def pop @queue.shift if @queue.empty? thread = @empty.first thread.wakeup if thread end end |