From 834b9e530e652b7ff7c5e222720bce3ad2b11c5f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 27 Jun 2012 04:18:53 +0200 Subject: Lock Cleanup (API Change) - LockExt -> ThreadLock - clarifying semantics (API Change) - ThreadLock: Remove isOwner(), use isOwner(Thread.currentThread) - adding @Override --- src/java/com/jogamp/common/util/locks/Lock.java | 1 + src/java/com/jogamp/common/util/locks/LockExt.java | 59 ---------------------- .../jogamp/common/util/locks/RecursiveLock.java | 2 +- .../util/locks/RecursiveThreadGroupLock.java | 2 + .../common/util/locks/SingletonInstance.java | 5 ++ .../com/jogamp/common/util/locks/ThreadLock.java | 59 ++++++++++++++++++++++ 6 files changed, 68 insertions(+), 60 deletions(-) delete mode 100644 src/java/com/jogamp/common/util/locks/LockExt.java create mode 100644 src/java/com/jogamp/common/util/locks/ThreadLock.java (limited to 'src/java/com/jogamp/common/util') diff --git a/src/java/com/jogamp/common/util/locks/Lock.java b/src/java/com/jogamp/common/util/locks/Lock.java index cf3fd01..33a093b 100644 --- a/src/java/com/jogamp/common/util/locks/Lock.java +++ b/src/java/com/jogamp/common/util/locks/Lock.java @@ -77,5 +77,6 @@ public interface Lock { */ void unlock() throws RuntimeException; + /** Query if locked */ boolean isLocked(); } diff --git a/src/java/com/jogamp/common/util/locks/LockExt.java b/src/java/com/jogamp/common/util/locks/LockExt.java deleted file mode 100644 index 974c11a..0000000 --- a/src/java/com/jogamp/common/util/locks/LockExt.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.common.util.locks; - -/** - * Extending the {@link Lock} features with convenient functionality. - */ -public interface LockExt extends Lock { - - /** - * @return the Thread owning this lock if locked, otherwise null - */ - Thread getOwner(); - - boolean isLockedByOtherThread(); - - boolean isOwner(); - - boolean isOwner(Thread thread); - - /** - * @throws RuntimeException if current thread does not hold the lock - */ - void validateLocked() throws RuntimeException; - - /** - * Execute the {@link Runnable Runnable taskAfterUnlockBeforeNotify} while holding the exclusive lock. - *

- * Then release the lock. - *

- */ - void unlock(Runnable taskAfterUnlockBeforeNotify); -} diff --git a/src/java/com/jogamp/common/util/locks/RecursiveLock.java b/src/java/com/jogamp/common/util/locks/RecursiveLock.java index efa9789..9eb9c8c 100644 --- a/src/java/com/jogamp/common/util/locks/RecursiveLock.java +++ b/src/java/com/jogamp/common/util/locks/RecursiveLock.java @@ -31,7 +31,7 @@ package com.jogamp.common.util.locks; /** * Reentrance capable locking toolkit. */ -public interface RecursiveLock extends LockExt { +public interface RecursiveLock extends ThreadLock { /** Return the number of locks issued to this lock by the same thread. * A hold count of 0 identifies this lock as unlocked.
* A hold count of 1 identifies this lock as locked.
diff --git a/src/java/com/jogamp/common/util/locks/RecursiveThreadGroupLock.java b/src/java/com/jogamp/common/util/locks/RecursiveThreadGroupLock.java index 5e11f29..626199f 100644 --- a/src/java/com/jogamp/common/util/locks/RecursiveThreadGroupLock.java +++ b/src/java/com/jogamp/common/util/locks/RecursiveThreadGroupLock.java @@ -123,6 +123,7 @@ public interface RecursiveThreadGroupLock extends RecursiveLock { * * {@inheritDoc} */ + @Override void unlock() throws RuntimeException; /** @@ -132,6 +133,7 @@ public interface RecursiveThreadGroupLock extends RecursiveLock { * * {@inheritDoc} */ + @Override void unlock(Runnable taskAfterUnlockBeforeNotify); } diff --git a/src/java/com/jogamp/common/util/locks/SingletonInstance.java b/src/java/com/jogamp/common/util/locks/SingletonInstance.java index c085371..5f2718b 100644 --- a/src/java/com/jogamp/common/util/locks/SingletonInstance.java +++ b/src/java/com/jogamp/common/util/locks/SingletonInstance.java @@ -68,8 +68,10 @@ public abstract class SingletonInstance implements Lock { public final long getPollPeriod() { return poll_ms; } public abstract String getName(); + @Override public final String toString() { return getName(); } + @Override public synchronized void lock() throws RuntimeException { try { do { @@ -82,6 +84,7 @@ public abstract class SingletonInstance implements Lock { } } + @Override public synchronized boolean tryLock(long maxwait) throws RuntimeException { if(locked) { return true; @@ -110,6 +113,7 @@ public abstract class SingletonInstance implements Lock { } protected abstract boolean tryLockImpl(); + @Override public void unlock() throws RuntimeException { if(locked) { locked = !unlockImpl(); @@ -121,6 +125,7 @@ public abstract class SingletonInstance implements Lock { } protected abstract boolean unlockImpl(); + @Override public synchronized boolean isLocked() { return locked; } diff --git a/src/java/com/jogamp/common/util/locks/ThreadLock.java b/src/java/com/jogamp/common/util/locks/ThreadLock.java new file mode 100644 index 0000000..65260bc --- /dev/null +++ b/src/java/com/jogamp/common/util/locks/ThreadLock.java @@ -0,0 +1,59 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.common.util.locks; + +/** + * Extending the {@link Lock} features with convenient functionality. + */ +public interface ThreadLock extends Lock { + + /** Query whether the lock is hold by the a thread other than the current thread. */ + boolean isLockedByOtherThread(); + + /** Query whether the lock is hold by the given thread. */ + boolean isOwner(Thread thread); + + /** + * @return the Thread owning this lock if locked, otherwise null + */ + Thread getOwner(); + + /** + * @throws RuntimeException if current thread does not hold the lock + */ + void validateLocked() throws RuntimeException; + + /** + * Execute the {@link Runnable Runnable taskAfterUnlockBeforeNotify} while holding the exclusive lock. + *

+ * Then release the lock. + *

+ */ + void unlock(Runnable taskAfterUnlockBeforeNotify); +} -- cgit v1.2.3