Class: Concurrent::LockFreeStack
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
self,
Enumerable,
Synchronization::Object ,
Synchronization::Volatile ,
Synchronization::AbstractObject
|
|
Inherits: |
Concurrent::Synchronization::Object
|
Defined in: | lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb |
Overview
**Edge Features** are under active development and may change frequently.
-
Deprecations are not added before incompatible changes.
-
Edge
version: major is always 0, minor bump means incompatible change, patch bump means compatible change. -
Edge
features may also lack tests and documentation. -
Features developed in
concurrent-ruby-edge
are expected to move toconcurrent-ruby
when finalised.
Constant Summary
-
EMPTY =
The singleton for empty node
Node[nil, nil]
Class Attribute Summary
Synchronization::Object
- Inherited
Class Method Summary
- .new(head = EMPTY) ⇒ LockFreeStack constructor
- .of1(value) private
- .of2(value1, value2) private
Synchronization::Object
- Inherited
.atomic_attribute?, .atomic_attributes, | |
.attr_atomic | Creates methods for reading and writing to a instance variable with volatile (Java) semantic as |
.attr_volatile | Creates methods for reading and writing (as |
.ensure_safe_initialization_when_final_fields_are_present | For testing purposes, quite slow. |
.new | Has to be called by children. |
.safe_initialization!, .define_initialize_atomic_fields |
Synchronization::AbstractObject
- Inherited
Instance Method Summary
- #clear ⇒ true, false
- #clear_each {|value| ... } ⇒ self
- #clear_if(head) ⇒ true, false
- #compare_and_clear(head) ⇒ true, false
- #compare_and_pop(head) ⇒ true, false
- #compare_and_push(head, value) ⇒ true, false
- #each(head = nil) ⇒ self
- #empty?(head = head()) ⇒ true, false
-
#inspect
Alias for #to_s.
- #peek ⇒ Node
- #pop ⇒ Object
- #push(value) ⇒ self
- #replace_if(head, new_head) ⇒ true, false
- #to_s ⇒ String (also: #inspect)
-
#compare_and_set_head(expected_head, new_head) ⇒ true, false
private
Sets the head to new_head if the current head is expected_head.
- #head ⇒ Object private
-
#head=(new_head) ⇒ Object
private
Set
the head. -
#swap_head(new_head) ⇒ Object
private
Set
the head to new_head and return the old head. -
#update_head {|Object| ... } ⇒ Object
private
Updates the head using the block.
Synchronization::Object
- Inherited
Synchronization::Volatile
- Included
Synchronization::AbstractObject
- Inherited
Constructor Details
.new(head = EMPTY) ⇒ LockFreeStack
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 51
def initialize(head = EMPTY) super() self.head = head end
Class Method Details
.of1(value) (private)
[ GitHub ].of2(value1, value2) (private)
[ GitHub ]Instance Method Details
#clear ⇒ true
, false
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 118
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 {|value| ... } ⇒ self
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 142
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
#clear_if(head) ⇒ true
, false
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 128
def clear_if(head) compare_and_set_head head, EMPTY end
#compare_and_clear(head) ⇒ true
, false
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 99
def compare_and_clear(head) compare_and_set_head head, EMPTY end
#compare_and_pop(head) ⇒ true
, false
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 85
def compare_and_pop(head) compare_and_set_head head, head.next_node end
#compare_and_push(head, value) ⇒ true
, false
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 65
def compare_and_push(head, value) compare_and_set_head head, Node[value, head] end
#compare_and_set_head(expected_head, new_head) ⇒ true
, false
(private)
Sets the head to new_head if the current head is expected_head
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 37
attr_atomic(:head)
#each(head = nil) ⇒ self
#empty?(head = head()) ⇒ true
, false
#head ⇒ Object (private)
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 37
attr_atomic(:head)
#head=(new_head) ⇒ Object (private)
Set
the head.
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 37
attr_atomic(:head)
#inspect
Alias for #to_s.
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 158
alias_method :inspect, :to_s
#peek ⇒ Node
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 79
def peek head end
#pop ⇒ Object
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 90
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) ⇒ self
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 71
def push(value) while true current_head = head return self if compare_and_set_head current_head, Node[value, current_head] end end
#replace_if(head, new_head) ⇒ true
, false
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 135
def replace_if(head, new_head) compare_and_set_head head, new_head end
#swap_head(new_head) ⇒ Object (private)
Set
the head to new_head and return the old head.
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 37
attr_atomic(:head)
#to_s ⇒ String
Also known as: #inspect
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 154
def to_s format '%s %s>', super[0..-2], to_a.to_s end
#update_head {|Object| ... } ⇒ Object (private)
Updates the head using the block.
# File 'lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb', line 37
attr_atomic(:head)