Top Inners Fields Constructors Methods
jogamp.common.util.locks

public Class RecursiveThreadGroupLockImpl01Unfairish

extends RecursiveLockImpl01Unfairish
implements RecursiveThreadGroupLock
Class Inheritance
All Implemented Interfaces
com.jogamp.common.util.locks.RecursiveThreadGroupLock, com.jogamp.common.util.locks.RecursiveLock, com.jogamp.common.util.locks.ThreadLock, com.jogamp.common.util.locks.Lock
Imports
java.util.Arrays, com.jogamp.common.util.locks.RecursiveThreadGroupLock

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Inherited from jogamp.common.util.locks.RecursiveLockImpl01Unfairish:
sync

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final void
addOwner(final Thread
the thread to be added to the list of additional owning threads
t
)

Implements com.jogamp.common.util.locks.RecursiveThreadGroupLock.addOwner.

Add a thread to the list of additional lock owners, which enables them to recursively claim this lock.
public final boolean
isOriginalOwner()

Implements com.jogamp.common.util.locks.RecursiveThreadGroupLock.isOriginalOwner.

Returns true if the current thread is the original lock owner, ie.
public final boolean
isOriginalOwner(final Thread thread)

Implements com.jogamp.common.util.locks.RecursiveThreadGroupLock.isOriginalOwner.

Returns true if the passed thread is the original lock owner, ie.
public final void
removeOwner(final Thread
the thread to be removed from the list of additional owning threads
t
)

Implements com.jogamp.common.util.locks.RecursiveThreadGroupLock.removeOwner.

Remove a thread from the list of additional lock owner threads.
public String
toString()

Overrides jogamp.common.util.locks.RecursiveLockImpl01Unfairish.toString.

Returns a string representation of the object.
public final void
unlock(final Runnable taskAfterUnlockBeforeNotify)

Overrides jogamp.common.util.locks.RecursiveLockImpl01Unfairish.unlock.

Implements com.jogamp.common.util.locks.RecursiveThreadGroupLock.unlock, com.jogamp.common.util.locks.ThreadLock.unlock.

Wait's until all additional owners released this lock before releasing it.

Inherited from jogamp.common.util.locks.RecursiveLockImpl01Unfairish:
getHoldCountgetLockedStackgetOwnergetQueueLengthisLockedisLockedByOtherThreadisOwnerlocksyncNamethreadNametryLockunlockvalidateLocked

Constructor Detail

RecursiveThreadGroupLockImpl01Unfairishback to summary
public RecursiveThreadGroupLockImpl01Unfairish()

Method Detail

addOwnerback to summary
public final void addOwner(final Thread t) throws RuntimeException, IllegalArgumentException

Implements com.jogamp.common.util.locks.RecursiveThreadGroupLock.addOwner.

Doc from com.jogamp.common.util.locks.RecursiveThreadGroupLock.addOwner.

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();
Parameters
t:Thread

the thread to be added to the list of additional owning threads

Annotations
@Override
Exceptions
RuntimeException:
if the current thread does not hold the lock.
IllegalArgumentException:
if the passed thread is the lock owner or already added.
isOriginalOwnerback to summary
public final boolean isOriginalOwner()

Implements com.jogamp.common.util.locks.RecursiveThreadGroupLock.isOriginalOwner.

Doc from 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.

Annotations
@Override
isOriginalOwnerback to summary
public final boolean isOriginalOwner(final Thread thread)

Implements com.jogamp.common.util.locks.RecursiveThreadGroupLock.isOriginalOwner.

Doc from com.jogamp.common.util.locks.RecursiveThreadGroupLock.isOriginalOwner.

Returns true if the passed thread is the original lock owner, ie. successfully claimed this lock the first time, ie. getHoldCount() == 1.

Annotations
@Override
removeOwnerback to summary
public final void removeOwner(final Thread t) throws RuntimeException, IllegalArgumentException

Implements com.jogamp.common.util.locks.RecursiveThreadGroupLock.removeOwner.

Doc from com.jogamp.common.util.locks.RecursiveThreadGroupLock.removeOwner.

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.

Parameters
t:Thread

the thread to be removed from the list of additional owning threads

Annotations
@Override
Exceptions
RuntimeException:
if the current thread does not hold the lock.
IllegalArgumentException:
if the passed thread is not added by addOwner(Thread)
toStringback to summary
public String toString()

Overrides jogamp.common.util.locks.RecursiveLockImpl01Unfairish.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
unlockback to summary
public final void unlock(final Runnable taskAfterUnlockBeforeNotify)

Overrides jogamp.common.util.locks.RecursiveLockImpl01Unfairish.unlock.

Implements com.jogamp.common.util.locks.RecursiveThreadGroupLock.unlock, com.jogamp.common.util.locks.ThreadLock.unlock.

Doc from com.jogamp.common.util.locks.RecursiveThreadGroupLock.unlock.

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.

Annotations
@Override
jogamp.common.util.locks back to summary

pack-priv Class RecursiveThreadGroupLockImpl01Unfairish.ThreadGroupSync

extends SingleThreadSync
Class Inheritance
Annotations
@SuppressWarnings:serial

Field Summary

Modifier and TypeField and Description
private int
private int
private Thread[]
private Thread

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public final void
addOwner(final Thread t)

pack-priv String
public final void
public final int
public final int
public final Thread
public final void
public final boolean
public final boolean
public final void
public final void
public final void
setWaitingOrigOwner(final Thread origOwner)

Inherited from jogamp.common.util.locks.RecursiveLockImpl01Unfairish.SingleThreadSync:
decrQSzgetHoldCountgetLockedStackgetOwnergetQSzincrQSzsetLockedStacksetOwner

Field Detail

holdCountAdditionOwnerback to summary
private int holdCountAdditionOwner
threadNumback to summary
private int threadNum
threadsback to summary
private Thread[] threads
waitingOrigOwnerback to summary
private Thread waitingOrigOwner

Constructor Detail

ThreadGroupSyncback to summary
pack-priv ThreadGroupSync()

Method Detail

addOwnerback to summary
public final void addOwner(final Thread t) throws IllegalArgumentException
addOwnerToStringback to summary
pack-priv String addOwnerToString()
decrHoldCountback to summary
public final void decrHoldCount(final Thread t)

Overrides jogamp.common.util.locks.RecursiveLockImpl01Unfairish.SingleThreadSync.decrHoldCount.

Implements jogamp.common.util.locks.RecursiveLockImpl01Unfairish.Sync.decrHoldCount.

Annotations
@Override
getAdditionalOwnerHoldCountback to summary
public final int getAdditionalOwnerHoldCount()
getAddOwnerCountback to summary
public final int getAddOwnerCount()
getWaitingOrigOwnerback to summary
public final Thread getWaitingOrigOwner()
incrHoldCountback to summary
public final void incrHoldCount(final Thread t)

Overrides jogamp.common.util.locks.RecursiveLockImpl01Unfairish.SingleThreadSync.incrHoldCount.

Implements jogamp.common.util.locks.RecursiveLockImpl01Unfairish.Sync.incrHoldCount.

Annotations
@Override
isOriginalOwnerback to summary
public final boolean isOriginalOwner(final Thread t)
isOwnerback to summary
public final boolean isOwner(final Thread t)

Overrides jogamp.common.util.locks.RecursiveLockImpl01Unfairish.SingleThreadSync.isOwner.

Implements jogamp.common.util.locks.RecursiveLockImpl01Unfairish.Sync.isOwner.

Annotations
@Override
removeAllOwnersback to summary
public final void removeAllOwners()
removeOwnerback to summary
public final void removeOwner(final Thread t) throws IllegalArgumentException
setWaitingOrigOwnerback to summary
public final void setWaitingOrigOwner(final Thread origOwner)