提交 c8018fbb 编写于 作者: D dl

8166507: ConcurrentSkipListSet.clear() can leave the Set in an invalid state

Reviewed-by: martin, smarks, psandoz
上级 58c67d13
...@@ -1655,7 +1655,24 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V> ...@@ -1655,7 +1655,24 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
* Removes all of the mappings from this map. * Removes all of the mappings from this map.
*/ */
public void clear() { public void clear() {
initialize(); for (;;) {
Node<K,V> b, n;
HeadIndex<K,V> h = head, d = (HeadIndex<K,V>)h.down;
if (d != null)
casHead(h, d); // remove levels
else if ((b = h.node) != null && (n = b.next) != null) {
Node<K,V> f = n.next; // remove values
if (n == b.next) {
Object v = n.value;
if (v == null)
n.helpDelete(b, f);
else if (n.casValue(v, null) && n.appendMarker(f))
b.casNext(n, f);
}
}
else
break;
}
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册