< prev index next >

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

Print this page

        

@@ -59,28 +59,53 @@
     protected AbstractOwnableSynchronizer() { }
 
     /**
      * The current owner of exclusive mode synchronization.
      */
-    private transient Thread exclusiveOwnerThread;
+    private transient Object exclusiveOwner;
+
+    /**
+     * Sets the strand that currently owns exclusive access.
+     * A {@code null} argument indicates that no strand owns access.
+     * This method does not otherwise impose any synchronization or
+     * {@code volatile} field accesses.
+     * @param owner the owner thread or fiber
+     */
+    protected final void setExclusiveOwner(Object owner) {
+        if (owner != null && !(owner instanceof Thread || owner instanceof Fiber))
+            throw new IllegalArgumentException();
+        exclusiveOwner = owner;
+    }
+
+    /**
+     * Returns the strand last set by {@code setExclusiveOwnerStrand}
+     * or {@code setExclusiveOwnerThread}, or {@code null} if never set.
+     * This method does not otherwise impose any synchronization or {@code
+     * volatile} field accesses.
+     * @return the owner thread
+     */
+    protected final Object getExclusiveOwner() {
+        return exclusiveOwner;
+    }
 
     /**
      * Sets the thread that currently owns exclusive access.
      * A {@code null} argument indicates that no thread owns access.
      * This method does not otherwise impose any synchronization or
      * {@code volatile} field accesses.
      * @param thread the owner thread
      */
     protected final void setExclusiveOwnerThread(Thread thread) {
-        exclusiveOwnerThread = thread;
+        exclusiveOwner = thread;
     }
 
     /**
      * Returns the thread last set by {@code setExclusiveOwnerThread},
      * or {@code null} if never set.  This method does not otherwise
      * impose any synchronization or {@code volatile} field accesses.
      * @return the owner thread
+     * @throws ClassCastException if the synchronizer is owned by a Fiber
      */
     protected final Thread getExclusiveOwnerThread() {
-        return exclusiveOwnerThread;
+        return (Thread) exclusiveOwner;
     }
 }
< prev index next >