< prev index next >

src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java

Print this page

        

*** 66,75 **** --- 66,77 ---- import java.util.function.ToIntBiFunction; import java.util.function.ToIntFunction; import java.util.function.ToLongBiFunction; import java.util.function.ToLongFunction; import java.util.stream.Stream; + + import jdk.internal.misc.Strands; import jdk.internal.misc.Unsafe; /** * A hash table supporting full concurrency of retrievals and * high expected concurrency for updates. This class obeys the
*** 2762,2772 **** * not) to complete before tree restructuring operations. */ static final class TreeBin<K,V> extends Node<K,V> { TreeNode<K,V> root; volatile TreeNode<K,V> first; ! volatile Thread waiter; volatile int lockState; // values for lockState static final int WRITER = 1; // set while holding write lock static final int WAITER = 2; // set when waiting for write lock static final int READER = 4; // increment value for setting read lock --- 2764,2774 ---- * not) to complete before tree restructuring operations. */ static final class TreeBin<K,V> extends Node<K,V> { TreeNode<K,V> root; volatile TreeNode<K,V> first; ! volatile Object waiter; volatile int lockState; // values for lockState static final int WRITER = 1; // set while holding write lock static final int WAITER = 2; // set when waiting for write lock static final int READER = 4; // increment value for setting read lock
*** 2864,2874 **** } } else if ((s & WAITER) == 0) { if (U.compareAndSetInt(this, LOCKSTATE, s, s | WAITER)) { waiting = true; ! waiter = Thread.currentThread(); } } else if (waiting) LockSupport.park(this); } --- 2866,2876 ---- } } else if ((s & WAITER) == 0) { if (U.compareAndSetInt(this, LOCKSTATE, s, s | WAITER)) { waiting = true; ! waiter = Strands.currentStrand(); } } else if (waiting) LockSupport.park(this); }
*** 2894,2904 **** TreeNode<K,V> r, p; try { p = ((r = root) == null ? null : r.findTreeNode(h, k, null)); } finally { ! Thread w; if (U.getAndAddInt(this, LOCKSTATE, -READER) == (READER|WAITER) && (w = waiter) != null) LockSupport.unpark(w); } return p; --- 2896,2906 ---- TreeNode<K,V> r, p; try { p = ((r = root) == null ? null : r.findTreeNode(h, k, null)); } finally { ! Object w; if (U.getAndAddInt(this, LOCKSTATE, -READER) == (READER|WAITER) && (w = waiter) != null) LockSupport.unpark(w); } return p;
< prev index next >