Skip to content

Commit

Permalink
cache: fix assert node.next=empty
Browse files Browse the repository at this point in the history
Change-Id: Idd337f2bebff2b03a5eefdfb9b189b9e012a7ae2
  • Loading branch information
javeme committed Mar 21, 2022
1 parent 730f332 commit 95a01ff
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ public LinkNode<K, V> enqueue(LinkNode<K, V> node) {
}

/*
* Link the node to the rear before to the last if we
* have not locked the node itself, because dumpKeys()
* Link the node to the `rear` before to the `last` if we
* have not locked the `node` itself, because dumpKeys()
* may get the new node with next=null.
* TODO: it also depends on memory barrier.
*/

// Build the link between `node` and the rear
// Build the link between `node` and the `rear`
node.next = this.rear;
assert this.rear.prev == last : this.rear.prev;
this.rear.prev = node;
Expand Down Expand Up @@ -445,12 +445,12 @@ public LinkNode<K, V> dequeue() {
continue;
}

// Break the link between the head and `first`
// Break the link between the `head` and `first`
assert first.next != null;
this.head.next = first.next;
first.next.prev = this.head;

// Clear the links of the first node
// Clear the links of the `first` node
first.prev = this.empty;
first.next = this.empty;

Expand All @@ -469,13 +469,12 @@ public LinkNode<K, V> remove(LinkNode<K, V> node) {
assert node != this.head && node != this.rear;

while (true) {
LinkNode<K, V> prev = node.prev;
if (prev == this.empty) {
assert node.next == this.empty;
// Ignore the node if it has been removed
if (node.prev == this.empty || node.next == this.empty) {
// Ignore the `node` if it has been removed
return null;
}

LinkNode<K, V> prev = node.prev;
List<Lock> locks = this.lock(prev, node);
try {
if (prev != node.prev) {
Expand All @@ -487,9 +486,10 @@ public LinkNode<K, V> remove(LinkNode<K, V> node) {
continue;
}
assert node.next != null : node;
assert node.next != this.empty : node.next;
assert node.next != node.prev : node.next;

// Build the link between node.prev and node.next
// Break `node` & Build the link between node.prev~node.next
node.prev.next = node.next;
node.next.prev = node.prev;

Expand Down

0 comments on commit 95a01ff

Please sign in to comment.