Skip to content

Commit

Permalink
fix prev may change after empty judgment
Browse files Browse the repository at this point in the history
Change-Id: I6814e588c67018b13fcefbc373f02912dbf08c6a
  • Loading branch information
javeme committed Mar 21, 2022
1 parent 95a01ff commit 0f7cef0
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ public LinkNode<K, V> enqueue(LinkNode<K, V> node) {

while (true) {
LinkNode<K, V> last = this.rear.prev;
assert last != this.empty : last;

// TODO: should we lock the new `node`?
List<Lock> locks = this.lock(last, this.rear);
Expand Down Expand Up @@ -446,7 +447,7 @@ public LinkNode<K, V> dequeue() {
}

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

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

while (true) {
if (node.prev == this.empty || node.next == this.empty) {
LinkNode<K, V> prev = node.prev;
if (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 Down

0 comments on commit 0f7cef0

Please sign in to comment.