Class: Daybreak::Queue Private

Inherits:
Object
  • Object
show all
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

API:

  • private

Direct Known Subclasses

Journal

Instance Method Summary collapse

Constructor Details

#initializeQueue

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.

API:

  • private



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.

API:

  • private



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

#closeObject

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.

API:

  • private



56
57
58
59
# File 'lib/daybreak/queue/mri.rb', line 56

def close
  @stop = true
  @heartbeat.join
end

#firstObject

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.

API:

  • private



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

#flushObject

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.

API:

  • private



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

#popObject

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.

API:

  • private



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