From 4374d11a3a204ab608402ee24a8cee14eff923ef Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 11 Dec 2011 04:10:34 +0100 Subject: 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. --- src/java/com/jogamp/common/util/locks/LockFactory.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/java/com/jogamp/common/util/locks/LockFactory.java') 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"); } -- cgit v1.2.3