Home | History | Annotate | Download | only in locks
      1 /*
      2  * Written by Doug Lea with assistance from members of JCP JSR-166
      3  * Expert Group and released to the public domain, as explained at
      4  * http://creativecommons.org/publicdomain/zero/1.0/
      5  */
      6 
      7 package java.util.concurrent.locks;
      8 
      9 /**
     10  * A synchronizer that may be exclusively owned by a thread.  This
     11  * class provides a basis for creating locks and related synchronizers
     12  * that may entail a notion of ownership.  The
     13  * {@code AbstractOwnableSynchronizer} class itself does not manage or
     14  * use this information. However, subclasses and tools may use
     15  * appropriately maintained values to help control and monitor access
     16  * and provide diagnostics.
     17  *
     18  * @since 1.6
     19  * @author Doug Lea
     20  */
     21 public abstract class AbstractOwnableSynchronizer
     22     implements java.io.Serializable {
     23 
     24     /** Use serial ID even though all fields transient. */
     25     private static final long serialVersionUID = 3737899427754241961L;
     26 
     27     /**
     28      * Empty constructor for use by subclasses.
     29      */
     30     protected AbstractOwnableSynchronizer() { }
     31 
     32     /**
     33      * The current owner of exclusive mode synchronization.
     34      */
     35     private transient Thread exclusiveOwnerThread;
     36 
     37     /**
     38      * Sets the thread that currently owns exclusive access.
     39      * A {@code null} argument indicates that no thread owns access.
     40      * This method does not otherwise impose any synchronization or
     41      * {@code volatile} field accesses.
     42      * @param thread the owner thread
     43      */
     44     protected final void setExclusiveOwnerThread(Thread thread) {
     45         exclusiveOwnerThread = thread;
     46     }
     47 
     48     /**
     49      * Returns the thread last set by {@code setExclusiveOwnerThread},
     50      * or {@code null} if never set.  This method does not otherwise
     51      * impose any synchronization or {@code volatile} field accesses.
     52      * @return the owner thread
     53      */
     54     protected final Thread getExclusiveOwnerThread() {
     55         return exclusiveOwnerThread;
     56     }
     57 }
     58