GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
RecursiveThreadGroupLock.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.common.util.locks;
29
30/**
31 * Reentrance capable locking toolkit, supporting multiple threads as owner.
32 * <p>
33 * See use case description at {@link #addOwner(Thread)}.
34 * </p>
35 */
36public interface RecursiveThreadGroupLock extends RecursiveLock {
37 /**
38 * Returns true if the current thread is the original lock owner, ie.
39 * successfully claimed this lock the first time, ie. {@link #getHoldCount()} == 1.
40 */
41 boolean isOriginalOwner();
42
43 /**
44 * Returns true if the passed thread is the original lock owner, ie.
45 * successfully claimed this lock the first time, ie. {@link #getHoldCount()} == 1.
46 */
47 boolean isOriginalOwner(Thread thread);
48
49 /**
50 * Add a thread to the list of additional lock owners, which enables them to recursively claim this lock.
51 * <p>
52 * The caller must hold this lock and be the original lock owner, see {@link #isOriginalOwner()}.
53 * </p>
54 * <p>
55 * If the original owner releases this lock via {@link #unlock()}
56 * all additional lock owners are released as well.
57 * This ensures consistency of spawn off additional lock owner threads and it's release.
58 * </p>
59 * Use case:
60 * <pre>
61 * Thread2 thread2 = new Thread2();
62 *
63 * Thread1 {
64 *
65 * // Claim this lock and become the original lock owner.
66 * lock.lock();
67 *
68 * try {
69 *
70 * // Allow Thread2 to claim the lock, ie. make thread2 an additional lock owner
71 * addOwner(thread2);
72 *
73 * // Start thread2
74 * thread2.start();
75 *
76 * // Wait until thread2 has finished requiring this lock, but keep thread2 running
77 * while(!thread2.waitForResult()) sleep();
78 *
79 * // Optional: Only if sure that this thread doesn't hold the lock anymore,
80 * // otherwise just release the lock via unlock().
81 * removeOwner(thread2);
82 *
83 * } finally {
84 *
85 * // Release this lock and remove all additional lock owners.
86 * // Implicit wait until thread2 gets off the lock.
87 * lock.unlock();
88 *
89 * }
90 *
91 * }.start();
92 * </pre>
93 *
94 * @param t the thread to be added to the list of additional owning threads
95 * @throws RuntimeException if the current thread does not hold the lock.
96 * @throws IllegalArgumentException if the passed thread is the lock owner or already added.
97 *
98 * @see #removeOwner(Thread)
99 * @see #unlock()
100 * @see #lock()
101 */
102 void addOwner(Thread t) throws RuntimeException, IllegalArgumentException;
103
104 /**
105 * Remove a thread from the list of additional lock owner threads.
106 * <p>
107 * The caller must hold this lock and be the original lock owner, see {@link #isOriginalOwner()}.
108 * </p>
109 * <p>
110 * Only use this method if sure that the thread doesn't hold the lock anymore.
111 * </p>
112 *
113 * @param t the thread to be removed from the list of additional owning threads
114 * @throws RuntimeException if the current thread does not hold the lock.
115 * @throws IllegalArgumentException if the passed thread is not added by {@link #addOwner(Thread)}
116 */
117 void removeOwner(Thread t) throws RuntimeException, IllegalArgumentException;
118
119 /**
120 * <p>
121 * Wait's until all additional owners released this lock before releasing it.
122 * </p>
123 *
124 * {@inheritDoc}
125 */
126 @Override
127 void unlock() throws RuntimeException;
128
129 /**
130 * <p>
131 * Wait's until all additional owners released this lock before releasing it.
132 * </p>
133 *
134 * {@inheritDoc}
135 */
136 @Override
137 void unlock(Runnable taskAfterUnlockBeforeNotify);
138
139}
Reentrance capable locking toolkit.
Reentrance capable locking toolkit, supporting multiple threads as owner.
void removeOwner(Thread t)
Remove a thread from the list of additional lock owner threads.
void addOwner(Thread t)
Add a thread to the list of additional lock owners, which enables them to recursively claim this lock...
boolean isOriginalOwner()
Returns true if the current thread is the original lock owner, ie.
boolean isOriginalOwner(Thread thread)
Returns true if the passed thread is the original lock owner, ie.