diff options
author | Sven Gothel <[email protected]> | 2011-12-11 04:10:34 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-12-11 04:10:34 +0100 |
commit | 4374d11a3a204ab608402ee24a8cee14eff923ef (patch) | |
tree | 6fcfa2b1b727e6df294a070fa67289bde335020a /src/java/com/jogamp/common/util/locks/LockFactory.java | |
parent | 8dc2ad6a130c75121bc35e393d1cab89217d4d63 (diff) |
RecursiveThreadGroupLock: New recursive lock interface and impl, allowing 'spawn off' process to become the lock owner.
To avoid complicated synchronization via synchronized, wait and notify between one thread
and a 'spawn' off thread which temporarly requires the hold lock,
RecursiveThreadGroupLock allows to add and remove other threads to become owners of the lock
as if they were the original holder.
This simplifies some rare locking use cases, eg. in JOGL's GLProfile initialization sequence
where a SharedResourceRunner thread is taking over initialization of shared resources.
Diffstat (limited to 'src/java/com/jogamp/common/util/locks/LockFactory.java')
-rw-r--r-- | src/java/com/jogamp/common/util/locks/LockFactory.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/java/com/jogamp/common/util/locks/LockFactory.java b/src/java/com/jogamp/common/util/locks/LockFactory.java index c374c2d..bb2d5f4 100644 --- a/src/java/com/jogamp/common/util/locks/LockFactory.java +++ b/src/java/com/jogamp/common/util/locks/LockFactory.java @@ -30,11 +30,12 @@ package com.jogamp.common.util.locks; import jogamp.common.util.locks.RecursiveLockImpl01CompleteFair; import jogamp.common.util.locks.RecursiveLockImpl01Unfairish; import jogamp.common.util.locks.RecursiveLockImplJava5; +import jogamp.common.util.locks.RecursiveThreadGroupLockImpl01Unfairish; public class LockFactory { public enum ImplType { - Int01(0), Java5(1); + Int01(0), Java5(1), Int02ThreadGroup(2); public final int id; @@ -48,12 +49,19 @@ public class LockFactory { return new RecursiveLockImpl01Unfairish(); } + /** default is ImplType.Int02ThreadGroup, unfair'ish (fastest w/ least deviation) */ + public static RecursiveThreadGroupLock createRecursiveThreadGroupLock() { + return new RecursiveThreadGroupLockImpl01Unfairish(); + } + public static RecursiveLock createRecursiveLock(ImplType t, boolean fair) { switch(t) { case Int01: return fair ? new RecursiveLockImpl01CompleteFair() : new RecursiveLockImpl01Unfairish(); case Java5: return new RecursiveLockImplJava5(fair); + case Int02ThreadGroup: + return new RecursiveThreadGroupLockImpl01Unfairish(); } throw new InternalError("XXX"); } |