class Concurrent::Edge::LockFreeStack

Constants

EMPTY

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/concurrent/edge/lock_free_stack.rb, line 28
def initialize
  super()
  self.head = EMPTY
end

Public Instance Methods

clear() click to toggle source
# File lib/concurrent/edge/lock_free_stack.rb, line 79
def clear
  while true
    current_head = head
    return false if current_head == EMPTY
    return true if compare_and_set_head current_head, EMPTY
  end
end
clear_each(&block) click to toggle source
# File lib/concurrent/edge/lock_free_stack.rb, line 87
def clear_each(&block)
  while true
    current_head = head
    return self if current_head == EMPTY
    if compare_and_set_head current_head, EMPTY
      each current_head, &block
      return self
    end
  end
end
compare_and_clear(head) click to toggle source
# File lib/concurrent/edge/lock_free_stack.rb, line 63
def compare_and_clear(head)
  compare_and_set_head head, EMPTY
end
compare_and_pop(head) click to toggle source
# File lib/concurrent/edge/lock_free_stack.rb, line 52
def compare_and_pop(head)
  compare_and_set_head head, head.next_node
end
compare_and_push(head, value) click to toggle source
# File lib/concurrent/edge/lock_free_stack.rb, line 37
def compare_and_push(head, value)
  compare_and_set_head head, Node[value, head]
end
each(head = nil) { |value| ... } click to toggle source
# File lib/concurrent/edge/lock_free_stack.rb, line 69
def each(head = nil)
  return to_enum(:each, head) unless block_given?
  it = head || peek
  until it.equal?(EMPTY)
    yield it.value
    it = it.next_node
  end
  self
end
empty?() click to toggle source
# File lib/concurrent/edge/lock_free_stack.rb, line 33
def empty?
  head.equal? EMPTY
end
peek() click to toggle source
# File lib/concurrent/edge/lock_free_stack.rb, line 48
def peek
  head
end
pop() click to toggle source
# File lib/concurrent/edge/lock_free_stack.rb, line 56
def pop
  while true
    current_head = head
    return current_head.value if compare_and_set_head current_head, current_head.next_node
  end
end
push(value) click to toggle source
# File lib/concurrent/edge/lock_free_stack.rb, line 41
def push(value)
  while true
    current_head = head
    return self if compare_and_set_head current_head, Node[value, current_head]
  end
end