Skip to content

Commit 10ddb2a

Browse files
committed
LockFreeLinkedSet: use camel case and move node to correct namespace
1 parent 6b476bb commit 10ddb2a

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

lib/concurrent/edge/lock_free_linked_set.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def add(item)
5555

5656
node = Node.new item, curr
5757

58-
if pred.SuccessorReference.compare_and_set curr, node, false, false
58+
if pred.Successor_reference.compare_and_set curr, node, false, false
5959
return true
6060
end
6161
end
@@ -88,7 +88,7 @@ def contains?(item)
8888

8989
while curr < item
9090
curr = curr.next_node
91-
marked = curr.SuccessorReference.marked?
91+
marked = curr.Successor_reference.marked?
9292
end
9393

9494
curr == item && !marked
@@ -109,11 +109,11 @@ def remove(item)
109109
return false if curr != item
110110

111111
succ = curr.next_node
112-
removed = curr.SuccessorReference.compare_and_set succ, succ, false, true
112+
removed = curr.Successor_reference.compare_and_set succ, succ, false, true
113113

114114
next_node unless removed
115115

116-
pred.SuccessorReference.compare_and_set curr, succ, false, false
116+
pred.Successor_reference.compare_and_set curr, succ, false, false
117117

118118
return true
119119
end
@@ -134,7 +134,7 @@ def each
134134

135135
until curr.last?
136136
curr = curr.next_node
137-
marked = curr.SuccessorReference.marked?
137+
marked = curr.Successor_reference.marked?
138138

139139
yield curr.Data unless marked
140140
end

lib/concurrent/edge/lock_free_linked_set/node.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class LockFreeLinkedSet
66
class Node < Synchronization::Object
77
include Comparable
88

9-
attr_reader :Data, :SuccessorReference, :Key
9+
attr_reader :Data, :Successor_reference, :Key
1010

1111
def initialize(data = nil, successor = nil)
1212
super()
1313

14-
@SuccessorReference = AtomicMarkableReference.new(successor || Tail.new)
14+
@Successor_reference = AtomicMarkableReference.new(successor || Tail.new)
1515
@Data = data
1616
@Key = key_for data
1717

@@ -20,13 +20,13 @@ def initialize(data = nil, successor = nil)
2020

2121
# Check to see if the node is the last in the list.
2222
def last?
23-
@SuccessorReference.value.is_a? Tail
23+
@Successor_reference.value.is_a? Tail
2424
end
2525

2626
# Next node in the list. Note: this is not the AtomicMarkableReference
2727
# of the next node, this is the actual Node itself.
2828
def next_node
29-
@SuccessorReference.value
29+
@Successor_reference.value
3030
end
3131

3232
# This method provides a unqiue key for the data which will be used for
@@ -49,7 +49,7 @@ def <=>(other)
4949
# a self-loop.
5050
class Tail < Node
5151
def initialize(_data = nil, _succ = nil)
52-
@SuccessorReference = AtomicMarkableReference.new self
52+
@Successor_reference = AtomicMarkableReference.new self
5353
end
5454

5555
# Always greater than other nodes. This means that traversal will end

lib/concurrent/edge/lock_free_linked_set/window.rb

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
11
module Concurrent
22
module Edge
3-
class Window
4-
attr_accessor :pred, :curr
3+
class LockFreeLinkedSet
4+
class Window
5+
attr_accessor :pred, :curr
56

6-
def initialize(pred, curr)
7-
@pred, @curr = pred, curr
8-
end
9-
10-
# This method is used to find a 'window' for which `add` and `remove`
11-
# methods can use to know where to add and remove from the list. However,
12-
# it has another responsibilility, which is to physically unlink any
13-
# nodes marked for removal in the set. This prevents adds/removes from
14-
# having to retraverse the list to physically unlink nodes.
15-
def self.find(head, item)
16-
loop do
17-
break_inner_loops = false
18-
pred = head
19-
curr = pred.next_node
7+
def initialize(pred, curr)
8+
@pred, @curr = pred, curr
9+
end
2010

11+
# This method is used to find a 'window' for which `add` and `remove`
12+
# methods can use to know where to add and remove from the list. However,
13+
# it has another responsibilility, which is to physically unlink any
14+
# nodes marked for removal in the set. This prevents adds/removes from
15+
# having to retraverse the list to physically unlink nodes.
16+
def self.find(head, item)
2117
loop do
22-
succ, marked = curr.SuccessorReference.get
18+
break_inner_loops = false
19+
pred = head
20+
curr = pred.next_node
2321

24-
# Remove sequence of marked nodes
25-
while marked
26-
removed = pred.SuccessorReference.compare_and_set curr, succ, false, false
22+
loop do
23+
succ, marked = curr.Successor_reference.get
2724

28-
# If could not remove node, try again
29-
break_inner_loops = true && break unless removed
25+
# Remove sequence of marked nodes
26+
while marked
27+
removed = pred.Successor_reference.compare_and_set curr, succ, false, false
3028

31-
curr = succ
32-
succ, marked = curr.SuccessorReference.get
33-
end
29+
# If could not remove node, try again
30+
break_inner_loops = true && break unless removed
31+
32+
curr = succ
33+
succ, marked = curr.Successor_reference.get
34+
end
3435

35-
break if break_inner_loops
36+
break if break_inner_loops
3637

37-
# We have found a window
38-
return new pred, curr if curr >= item
38+
# We have found a window
39+
return new pred, curr if curr >= item
3940

40-
pred = curr
41-
curr = succ
41+
pred = curr
42+
curr = succ
43+
end
4244
end
4345
end
4446
end

0 commit comments

Comments
 (0)