< prev index next >

src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java

Print this page
8234131: Miscellaneous changes imported from jsr166 CVS 2020-12
Reviewed-by: martin

@@ -38,10 +38,11 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.RejectedExecutionException;
 import jdk.internal.misc.Unsafe;
 
 /**
  * A version of {@link AbstractQueuedSynchronizer} in
  * which synchronization state is maintained as a {@code long}.

@@ -1195,17 +1196,22 @@
          */
         public final void awaitUninterruptibly() {
             ConditionNode node = new ConditionNode();
             long savedState = enableWait(node);
             LockSupport.setCurrentBlocker(this); // for back-compatibility
-            boolean interrupted = false;
+            boolean interrupted = false, rejected = false;
             while (!canReacquire(node)) {
                 if (Thread.interrupted())
                     interrupted = true;
                 else if ((node.status & COND) != 0) {
                     try {
+                        if (rejected)
+                            node.block();
+                        else
                         ForkJoinPool.managedBlock(node);
+                    } catch (RejectedExecutionException ex) {
+                        rejected = true;
                     } catch (InterruptedException ie) {
                         interrupted = true;
                     }
                 } else
                     Thread.onSpinWait();    // awoke while enqueuing

@@ -1234,18 +1240,23 @@
             if (Thread.interrupted())
                 throw new InterruptedException();
             ConditionNode node = new ConditionNode();
             long savedState = enableWait(node);
             LockSupport.setCurrentBlocker(this); // for back-compatibility
-            boolean interrupted = false, cancelled = false;
+            boolean interrupted = false, cancelled = false, rejected = false;
             while (!canReacquire(node)) {
                 if (interrupted |= Thread.interrupted()) {
                     if (cancelled = (node.getAndUnsetStatus(COND) & COND) != 0)
                         break;              // else interrupted after signal
                 } else if ((node.status & COND) != 0) {
                     try {
+                        if (rejected)
+                            node.block();
+                        else
                         ForkJoinPool.managedBlock(node);
+                    } catch (RejectedExecutionException ex) {
+                        rejected = true;
                     } catch (InterruptedException ie) {
                         interrupted = true;
                     }
                 } else
                     Thread.onSpinWait();    // awoke while enqueuing
< prev index next >