From 3ed491213f8f7f05d7b9866b50d764370d8ff5f6 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 25 Mar 2012 03:29:53 +0200 Subject: 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! --- src/jogl/classes/javax/media/opengl/Threading.java | 44 ++++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'src/jogl/classes/javax/media/opengl/Threading.java') 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 isOpenGLThread() 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()} and not {@link #isOpenGLThread()} + * and the lock is not being hold by this thread, + * invoke Runnable r on the OpenGL thread via {@link #invokeOnOpenGLThread(boolean, Runnable)}. + *

+ * Otherwise invoke Runnable r on the current thread. + *

+ * + * @param wait set to true for waiting until Runnable r 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(); + } } } -- cgit v1.2.3