diff options
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/GLWorkerThread.java')
-rw-r--r-- | src/jogl/classes/jogamp/opengl/GLWorkerThread.java | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLWorkerThread.java b/src/jogl/classes/jogamp/opengl/GLWorkerThread.java index f7d59e127..131e6f3ac 100644 --- a/src/jogl/classes/jogamp/opengl/GLWorkerThread.java +++ b/src/jogl/classes/jogamp/opengl/GLWorkerThread.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution 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. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,11 +28,11 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ @@ -67,7 +67,7 @@ public class GLWorkerThread { private static volatile Runnable work; // Queue of Runnables to be asynchronously invoked private static List<Runnable> queue = new ArrayList<Runnable>(); - + /** Should only be called by Threading class if creation of the GLWorkerThread was requested via the opengl.1thread system property. <br> @@ -86,7 +86,7 @@ public class GLWorkerThread { thread.start(); try { lock.wait(); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } } @@ -149,7 +149,7 @@ public class GLWorkerThread { } } - public static void invoke(boolean wait, Runnable runnable) + public static void invoke(final boolean wait, final Runnable runnable) throws InvocationTargetException, InterruptedException { if(wait) { invokeAndWait(runnable); @@ -157,14 +157,14 @@ public class GLWorkerThread { invokeLater(runnable); } } - - public static void invokeAndWait(Runnable runnable) + + public static void invokeAndWait(final Runnable runnable) throws InvocationTargetException, InterruptedException { if (!started) { throw new RuntimeException(getThreadName()+": May not invokeAndWait on worker thread without starting it first"); } - Object lockTemp = lock; + final Object lockTemp = lock; if (lockTemp == null) { return; // Terminating } @@ -179,19 +179,19 @@ public class GLWorkerThread { lockTemp.notifyAll(); lockTemp.wait(); if (exception != null) { - Throwable localException = exception; + final Throwable localException = exception; exception = null; throw new InvocationTargetException(localException); } } } - public static void invokeLater(Runnable runnable) { + public static void invokeLater(final Runnable runnable) { if (!started) { throw new RuntimeException(getThreadName()+": May not invokeLater on worker thread without starting it first"); } - Object lockTemp = lock; + final Object lockTemp = lock; if (lockTemp == null) { return; // Terminating } @@ -219,11 +219,10 @@ public class GLWorkerThread { return (Thread.currentThread() == thread); } - protected static String getThreadName() { - return Thread.currentThread().getName(); - } - + protected static String getThreadName() { return Thread.currentThread().getName(); } + static class WorkerRunnable implements Runnable { + @Override public void run() { // Notify starting thread that we're ready synchronized (lock) { @@ -238,7 +237,7 @@ public class GLWorkerThread { try { // Avoid race conditions with wanting to release contexts on this thread lock.wait(1000); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } if (GLContext.getCurrent() != null) { @@ -246,7 +245,7 @@ public class GLWorkerThread { break; } } - + if (shouldTerminate) { lock.notifyAll(); thread = null; @@ -257,7 +256,7 @@ public class GLWorkerThread { if (work != null) { try { work.run(); - } catch (Throwable t) { + } catch (final Throwable t) { exception = t; } finally { work = null; @@ -267,19 +266,19 @@ public class GLWorkerThread { while (!queue.isEmpty()) { try { - Runnable curAsync = queue.remove(0); + final Runnable curAsync = queue.remove(0); curAsync.run(); - } catch (Throwable t) { + } catch (final Throwable t) { System.err.println(getThreadName()+": Exception occurred on JOGL OpenGL worker thread:"); t.printStackTrace(); } } // See about releasing current context - GLContext curContext = GLContext.getCurrent(); + final GLContext curContext = GLContext.getCurrent(); if (curContext != null && (curContext instanceof GLContextImpl)) { - GLContextImpl impl = (GLContextImpl) curContext; + final GLContextImpl impl = (GLContextImpl) curContext; if (impl.hasWaiters()) { impl.release(); } |