# File lib/celluloid/logging/ring_buffer.rb, line 3 def initialize(size) @size = size @start = 0 @count = 0 @buffer = Array.new(size) @mutex = Mutex.new end
# File lib/celluloid/logging/ring_buffer.rb, line 49 def clear @buffer = Array.new(@size) @start = 0 @count = 0 end
# File lib/celluloid/logging/ring_buffer.rb, line 15 def empty? @count == 0 end
# File lib/celluloid/logging/ring_buffer.rb, line 39 def flush values = [] @mutex.synchronize do while !empty? values << remove_element end end values end
# File lib/celluloid/logging/ring_buffer.rb, line 11 def full? @count == @size end
# File lib/celluloid/logging/ring_buffer.rb, line 19 def push(value) @mutex.synchronize do stop = (@start + @count) % @size @buffer[stop] = value if full? @start = (@start + 1) % @size else @count += 1 end value end end
# File lib/celluloid/logging/ring_buffer.rb, line 33 def shift @mutex.synchronize do remove_element end end
# File lib/celluloid/logging/ring_buffer.rb, line 57 def remove_element return nil if empty? value, @buffer[@start] = @buffer[@start], nil @start = (@start + 1) % @size @count -= 1 value end