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  * @author Doug Lea
26  */
27 abstract class AbstractOwnableSynchronizer {
28 
29     /**
30      * Empty constructor for use by subclasses.
31      */
32     protected this() { }
33 
34     /**
35      * The current owner of exclusive mode synchronization.
36      */
37     private Thread exclusiveOwnerThread;
38 
39     /**
40      * Sets the thread that currently owns exclusive access.
41      * A {@code null} argument indicates that no thread owns access.
42      * This method does not otherwise impose any synchronization or
43      * {@code volatile} field accesses.
44      * @param thread the owner thread
45      */
46     protected final void setExclusiveOwnerThread(Thread thread) {
47         exclusiveOwnerThread = thread;
48     }
49 
50     /**
51      * Returns the thread last set by {@code setExclusiveOwnerThread},
52      * or {@code null} if never set.  This method does not otherwise
53      * impose any synchronization or {@code volatile} field accesses.
54      * @return the owner thread
55      */
56     protected final Thread getExclusiveOwnerThread() {
57         return exclusiveOwnerThread;
58     }
59 }