diff options
author | Sven Gothel <[email protected]> | 2012-03-25 03:29:53 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-03-25 03:29:53 +0200 |
commit | 3ed491213f8f7f05d7b9866b50d764370d8ff5f6 (patch) | |
tree | 07ea2547be486eb50db9d79a19f6e0c4dfa4dc70 /src/jogl/classes/javax/media/opengl/Threading.java | |
parent | 45a42f7c7f7fce4e6c7eb495591c438bdf0170a2 (diff) |
Enhance and generalize AWT Threading* implementation; Minor changes ..
Threading*:
- add invoke(..) generalizing the Therading decision
GLCanvas:
- remove 'manual' Threading decision, simply call Threading.invoke(..)
- use anonymous Runnable instances
- remove drawable lock, drawable is volatile instead
GLJPanel:
- remove 'manual' Threading decision, simply call Threading.invoke(..)
- use anonymous Runnable instances
- DEBUG: Use getThreadName() prefix
GLContextImpl:
- Remove GLWorkerThread idle command on makeCurrent(),
no holding of context in worker thread while idle.
- DEBUG: Use getThreadName() prefix
X11GLXContext:
- DEBUG: Use getThreadName() prefix
TODO: Validate whether it's OK for GLCanvas and GLJPanel to set Threading.Mode.MT as the default mode!
Diffstat (limited to 'src/jogl/classes/javax/media/opengl/Threading.java')
-rw-r--r-- | src/jogl/classes/javax/media/opengl/Threading.java | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/jogl/classes/javax/media/opengl/Threading.java b/src/jogl/classes/javax/media/opengl/Threading.java index 4871c1dd7..4788f9cf6 100644 --- a/src/jogl/classes/javax/media/opengl/Threading.java +++ b/src/jogl/classes/javax/media/opengl/Threading.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2012 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 @@ -39,7 +40,7 @@ package javax.media.opengl; -import jogamp.opengl.*; +import jogamp.opengl.ThreadingImpl; /** This API provides access to the threading model for the implementation of the classes in this package. @@ -133,21 +134,27 @@ public class Threading { once disabled, partly to discourage careless use of this method. This method should be called as early as possible in an application. */ - public static void disableSingleThreading() { + public static final void disableSingleThreading() { ThreadingImpl.disableSingleThreading(); } /** Indicates whether OpenGL work is being automatically forced to a single thread in this implementation. */ - public static boolean isSingleThreaded() { + public static final boolean isSingleThreaded() { return ThreadingImpl.isSingleThreaded(); } + /** Indicates whether the current thread is the designated toolkit thread, + if such semantics exists. */ + public static final boolean isToolkitThread() throws GLException { + return ThreadingImpl.isToolkitThread(); + } + /** Indicates whether the current thread is the single thread on which this implementation of the javax.media.opengl APIs performs all of its OpenGL-related work. This method should only be called if the single-thread model is in effect. */ - public static boolean isOpenGLThread() throws GLException { + public static final boolean isOpenGLThread() throws GLException { return ThreadingImpl.isOpenGLThread(); } @@ -159,8 +166,31 @@ public class Threading { thread (i.e., if <code>isOpenGLThread()</code> returns false). It is up to the end user to check to see whether the current thread is the OpenGL thread and either execute the - Runnable directly or perform the work inside it. */ - public static void invokeOnOpenGLThread(Runnable r) throws GLException { - ThreadingImpl.invokeOnOpenGLThread(r); + Runnable directly or perform the work inside it. + **/ + public static final void invokeOnOpenGLThread(boolean wait, Runnable r) throws GLException { + ThreadingImpl.invokeOnOpenGLThread(wait, r); + } + + /** + * If {@link #isSingleThreaded()} <b>and</b> not {@link #isOpenGLThread()} + * <b>and</b> the <code>lock</code> is not being hold by this thread, + * invoke Runnable <code>r</code> on the OpenGL thread via {@link #invokeOnOpenGLThread(boolean, Runnable)}. + * <p> + * Otherwise invoke Runnable <code>r</code> on the current thread. + * </p> + * + * @param wait set to true for waiting until Runnable <code>r</code> is finished, otherwise false. + * @param r the Runnable to be executed + * @param lock optional lock object to be tested + * @throws GLException + */ + public static final void invoke(boolean wait, Runnable r, Object lock) throws GLException { + if ( isSingleThreaded() && !isOpenGLThread() && + ( null == lock || !Thread.holdsLock(lock) ) ) { + invokeOnOpenGLThread(wait, r); + } else { + r.run(); + } } } |