lib/daybreak/queue/mri.rb in daybreak-0.2.1 vs lib/daybreak/queue/mri.rb in daybreak-0.2.2

- old
+ new

@@ -1,10 +1,14 @@ module Daybreak + # A queue for ruby implementations with a GIL + # + # HACK: Dangerous optimization on MRI which has a + # global interpreter lock and makes the @queue array + # thread safe. + # + # @api private class Queue - # HACK: Dangerous optimization on MRI which has a - # global interpreter lock and makes the @queue array - # thread safe. def initialize @queue, @full, @empty = [], [], [] @stop = false @heartbeat = Thread.new(&method(:heartbeat)) @heartbeat.priority = -9 @@ -22,11 +26,11 @@ thread = @empty.first thread.wakeup if thread end end - def next + 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? @@ -47,11 +51,11 @@ @empty.delete(Thread.current) end end end - def stop + def close @stop = true @heartbeat.join end private @@ -64,6 +68,6 @@ @full.each(&:wakeup) sleep 0.1 end end end -end \ No newline at end of file +end