|
GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java (public API).
|
Reentrance capable locking toolkit, supporting multiple threads as owner. More...
Public Member Functions | |
| boolean | isOriginalOwner () |
| Returns true if the current thread is the original lock owner, ie. More... | |
| boolean | isOriginalOwner (Thread thread) |
| Returns true if the passed thread is the original lock owner, ie. More... | |
| void | addOwner (Thread t) throws RuntimeException, IllegalArgumentException |
| Add a thread to the list of additional lock owners, which enables them to recursively claim this lock. More... | |
| void | removeOwner (Thread t) throws RuntimeException, IllegalArgumentException |
| Remove a thread from the list of additional lock owner threads. More... | |
| void | unlock () throws RuntimeException |
| void | unlock (Runnable taskAfterUnlockBeforeNotify) |
Public Member Functions inherited from com.jogamp.common.util.locks.RecursiveLock | |
| int | getHoldCount () |
| Return the number of locks issued to this lock by the same thread. More... | |
| int | getQueueLength () |
Public Member Functions inherited from com.jogamp.common.util.locks.ThreadLock | |
| boolean | isLockedByOtherThread () |
| Query whether the lock is hold by the a thread other than the current thread. More... | |
| boolean | isOwner (Thread thread) |
| Query whether the lock is hold by the given thread. More... | |
| Thread | getOwner () |
| void | validateLocked () throws RuntimeException |
| void | unlock (Runnable taskAfterUnlockBeforeNotify) |
Execute the Runnable taskAfterUnlockBeforeNotify while holding the exclusive lock. More... | |
Public Member Functions inherited from com.jogamp.common.util.locks.Lock | |
| void | lock () throws RuntimeException |
Blocking until the lock is acquired by this Thread or TIMEOUT is reached. More... | |
| boolean | tryLock (long timeout) throws InterruptedException |
Blocking until the lock is acquired by this Thread or maxwait in ms is reached. More... | |
| void | unlock () throws RuntimeException |
| Release the lock. More... | |
| boolean | isLocked () |
| Query if locked. More... | |
Additional Inherited Members | |
Static Public Attributes inherited from com.jogamp.common.util.locks.Lock | |
| static final boolean | DEBUG = Debug.debug("Lock") |
Enable via the property jogamp.debug.Lock More... | |
| static final boolean | TRACE_LOCK = Debug.isPropertyDefined("jogamp.debug.Lock.TraceLock", true) |
Enable via the property jogamp.debug.Lock.TraceLock More... | |
| static final long | DEFAULT_TIMEOUT = 5000 |
The default TIMEOUT value, of {@value} ms. More... | |
| static final long | TIMEOUT = Debug.getLongProperty("jogamp.common.utils.locks.Lock.timeout", true, DEFAULT_TIMEOUT) |
The TIMEOUT for lock() in ms, defaults to DEFAULT_TIMEOUT. More... | |
Reentrance capable locking toolkit, supporting multiple threads as owner.
See use case description at addOwner(Thread).
Definition at line 36 of file RecursiveThreadGroupLock.java.
| void com.jogamp.common.util.locks.RecursiveThreadGroupLock.addOwner | ( | Thread | t | ) | throws RuntimeException, IllegalArgumentException |
Add a thread to the list of additional lock owners, which enables them to recursively claim this lock.
The caller must hold this lock and be the original lock owner, see isOriginalOwner().
If the original owner releases this lock via unlock() all additional lock owners are released as well. This ensures consistency of spawn off additional lock owner threads and it's release.
Use case:
Thread2 thread2 = new Thread2();
Thread1 {
// Claim this lock and become the original lock owner.
lock.lock();
try {
// Allow Thread2 to claim the lock, ie. make thread2 an additional lock owner
addOwner(thread2);
// Start thread2
thread2.start();
// Wait until thread2 has finished requiring this lock, but keep thread2 running
while(!thread2.waitForResult()) sleep();
// Optional: Only if sure that this thread doesn't hold the lock anymore,
// otherwise just release the lock via unlock().
removeOwner(thread2);
} finally {
// Release this lock and remove all additional lock owners.
// Implicit wait until thread2 gets off the lock.
lock.unlock();
}
}.start();
| t | the thread to be added to the list of additional owning threads |
| RuntimeException | if the current thread does not hold the lock. |
| IllegalArgumentException | if the passed thread is the lock owner or already added. |
| boolean com.jogamp.common.util.locks.RecursiveThreadGroupLock.isOriginalOwner | ( | ) |
Returns true if the current thread is the original lock owner, ie.
successfully claimed this lock the first time, ie. getHoldCount() == 1.
| boolean com.jogamp.common.util.locks.RecursiveThreadGroupLock.isOriginalOwner | ( | Thread | thread | ) |
Returns true if the passed thread is the original lock owner, ie.
successfully claimed this lock the first time, ie. getHoldCount() == 1.
| void com.jogamp.common.util.locks.RecursiveThreadGroupLock.removeOwner | ( | Thread | t | ) | throws RuntimeException, IllegalArgumentException |
Remove a thread from the list of additional lock owner threads.
The caller must hold this lock and be the original lock owner, see isOriginalOwner().
Only use this method if sure that the thread doesn't hold the lock anymore.
| t | the thread to be removed from the list of additional owning threads |
| RuntimeException | if the current thread does not hold the lock. |
| IllegalArgumentException | if the passed thread is not added by addOwner(Thread) |
| void com.jogamp.common.util.locks.RecursiveThreadGroupLock.unlock | ( | ) | throws RuntimeException |
Wait's until all additional owners released this lock before releasing it.
Release the lock.
| RuntimeException | in case the lock is not acquired by this thread. |
Implements com.jogamp.common.util.locks.Lock.
| void com.jogamp.common.util.locks.RecursiveThreadGroupLock.unlock | ( | Runnable | taskAfterUnlockBeforeNotify | ) |
Wait's until all additional owners released this lock before releasing it.
Execute the Runnable taskAfterUnlockBeforeNotify while holding the exclusive lock.Then release the lock.
Implements com.jogamp.common.util.locks.ThreadLock.