rt/emul/compact/src/main/java/java/util/concurrent/locks/AbstractOwnableSynchronizer.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/locks/AbstractOwnableSynchronizer.java Sat Mar 19 10:46:31 2016 +0100
1.3 @@ -0,0 +1,86 @@
1.4 +/*
1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.6 + *
1.7 + * This code is free software; you can redistribute it and/or modify it
1.8 + * under the terms of the GNU General Public License version 2 only, as
1.9 + * published by the Free Software Foundation. Oracle designates this
1.10 + * particular file as subject to the "Classpath" exception as provided
1.11 + * by Oracle in the LICENSE file that accompanied this code.
1.12 + *
1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.16 + * version 2 for more details (a copy is included in the LICENSE file that
1.17 + * accompanied this code).
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License version
1.20 + * 2 along with this work; if not, write to the Free Software Foundation,
1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.22 + *
1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.24 + * or visit www.oracle.com if you need additional information or have any
1.25 + * questions.
1.26 + */
1.27 +
1.28 +/*
1.29 + * This file is available under and governed by the GNU General Public
1.30 + * License version 2 only, as published by the Free Software Foundation.
1.31 + * However, the following notice accompanied the original version of this
1.32 + * file:
1.33 + *
1.34 + * Written by Doug Lea with assistance from members of JCP JSR-166
1.35 + * Expert Group and released to the public domain, as explained at
1.36 + * http://creativecommons.org/publicdomain/zero/1.0/
1.37 + */
1.38 +
1.39 +package java.util.concurrent.locks;
1.40 +
1.41 +/**
1.42 + * A synchronizer that may be exclusively owned by a thread. This
1.43 + * class provides a basis for creating locks and related synchronizers
1.44 + * that may entail a notion of ownership. The
1.45 + * <tt>AbstractOwnableSynchronizer</tt> class itself does not manage or
1.46 + * use this information. However, subclasses and tools may use
1.47 + * appropriately maintained values to help control and monitor access
1.48 + * and provide diagnostics.
1.49 + *
1.50 + * @since 1.6
1.51 + * @author Doug Lea
1.52 + */
1.53 +public abstract class AbstractOwnableSynchronizer
1.54 + implements java.io.Serializable {
1.55 +
1.56 + /** Use serial ID even though all fields transient. */
1.57 + private static final long serialVersionUID = 3737899427754241961L;
1.58 +
1.59 + /**
1.60 + * Empty constructor for use by subclasses.
1.61 + */
1.62 + protected AbstractOwnableSynchronizer() { }
1.63 +
1.64 + /**
1.65 + * The current owner of exclusive mode synchronization.
1.66 + */
1.67 + private transient Thread exclusiveOwnerThread;
1.68 +
1.69 + /**
1.70 + * Sets the thread that currently owns exclusive access. A
1.71 + * <tt>null</tt> argument indicates that no thread owns access.
1.72 + * This method does not otherwise impose any synchronization or
1.73 + * <tt>volatile</tt> field accesses.
1.74 + */
1.75 + protected final void setExclusiveOwnerThread(Thread t) {
1.76 + exclusiveOwnerThread = t;
1.77 + }
1.78 +
1.79 + /**
1.80 + * Returns the thread last set by
1.81 + * <tt>setExclusiveOwnerThread</tt>, or <tt>null</tt> if never
1.82 + * set. This method does not otherwise impose any synchronization
1.83 + * or <tt>volatile</tt> field accesses.
1.84 + * @return the owner thread
1.85 + */
1.86 + protected final Thread getExclusiveOwnerThread() {
1.87 + return exclusiveOwnerThread;
1.88 + }
1.89 +}