1 /* 2 * Hunt - A refined core library for D programming language. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net/ 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.concurrency.AbstractOwnableSynchronizer; 13 14 import core.thread; 15 16 /** 17 * A synchronizer that may be exclusively owned by a thread. This 18 * class provides a basis for creating locks and related synchronizers 19 * that may entail a notion of ownership. The 20 * {@code AbstractOwnableSynchronizer} class itself does not manage or 21 * use this information. However, subclasses and tools may use 22 * appropriately maintained values to help control and monitor access 23 * and provide diagnostics. 24 * 25 * @since 1.6 26 * @author Doug Lea 27 */ 28 abstract class AbstractOwnableSynchronizer { 29 30 /** 31 * Empty constructor for use by subclasses. 32 */ 33 protected this() { } 34 35 /** 36 * The current owner of exclusive mode synchronization. 37 */ 38 private Thread exclusiveOwnerThread; 39 40 /** 41 * Sets the thread that currently owns exclusive access. 42 * A {@code null} argument indicates that no thread owns access. 43 * This method does not otherwise impose any synchronization or 44 * {@code volatile} field accesses. 45 * @param thread the owner thread 46 */ 47 protected final void setExclusiveOwnerThread(Thread thread) { 48 exclusiveOwnerThread = thread; 49 } 50 51 /** 52 * Returns the thread last set by {@code setExclusiveOwnerThread}, 53 * or {@code null} if never set. This method does not otherwise 54 * impose any synchronization or {@code volatile} field accesses. 55 * @return the owner thread 56 */ 57 protected final Thread getExclusiveOwnerThread() { 58 return exclusiveOwnerThread; 59 } 60 }