class Concurrent::LockFreeStack
@!macro warn.edge
Constants
- EMPTY
-
The singleton for empty node
Public Class Methods
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 49 def initialize(head = EMPTY) super() self.head = head end
@param [Node] head
Calls superclass method
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 39 def self.of1(value) new Node[value, EMPTY] end
@!visibility private
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 44 def self.of2(value1, value2) new Node[value1, Node[value2, EMPTY]] end
@!visibility private
Public Instance Methods
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 116 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
@return [true, false]
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 140 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
@return [self] @yield over the cleared stack @yieldparam [Object] value
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 126 def clear_if(head) compare_and_set_head head, EMPTY end
@param [Node] head @return [true, false]
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 97 def compare_and_clear(head) compare_and_set_head head, EMPTY end
@param [Node] head @return [true, false]
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 83 def compare_and_pop(head) compare_and_set_head head, head.next_node end
@param [Node] head @return [true, false]
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 63 def compare_and_push(head, value) compare_and_set_head head, Node[value, head] end
@param [Node] head @param [Object] value @return [true, false]
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 105 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
@param [Node] head @return [self]
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 56 def empty?(head = head()) head.equal? EMPTY end
@param [Node] head @return [true, false]
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 77 def peek head end
@return [Node]
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 88 def pop while true current_head = head return current_head.value if compare_and_set_head current_head, current_head.next_node end end
@return [Object]
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 69 def push(value) while true current_head = head return self if compare_and_set_head current_head, Node[value, current_head] end end
@param [Object] value @return [self]
Source
# File lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb, line 133 def replace_if(head, new_head) compare_and_set_head head, new_head end
@param [Node] head @param [Node] new_head @return [true, false]