From 9291731fec7103301ba36511ceb4375f63170e5c Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sun, 11 Dec 2011 04:47:27 +0100
Subject: Fix concurrency bug of GLProfile initialization ; Fix
 SharedResourceRunner 'dead' thread (Applets)

GLDrawableFactory:
  - clarify: public getWasSharedContextCreated(..) -> protected createSharedResource(..)
  - add: getSharesResourceThread()

GLProfile:
  - proper locking of initSingletion(..) path:
    - Use RecursiveThreadGroupLock and add/remove GLDrawableFactory's sharesResourceThread
      while creating it's the sharedResource.
      This simplifies and fixes GLProfile's locking code.

  - Fix and simplify initSingleton(boolean) API doc - mark it deprecated.

  - Add initSingleton() for controlled initialization only, pairing w/ shutdown(..)

Remove initSingleton(boolean) calls in code and test!

+++

Fix SharedResourceRunner 'dead' thread (Applets)
  In Applets, stopping an Applet makes the browser Java plugin interrupting
  and killing all related threads, including our SharedResourceRunner thread.

  - Validate whether the shared resource thread is alive

  - Catch interruption in shared resource thread and assume it's a kill signal

  - releaseSharedResource: clear devicesTried set
---
 .../opengl/windows/wgl/WindowsWGLDrawableFactory.java   | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

(limited to 'src/jogl/classes/jogamp/opengl/windows')

diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
index 917402b0a..43c16240d 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
@@ -119,17 +119,14 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
     
         // Init shared resources off thread
         // Will be released via ShutdownHook
-        sharedResourceImpl = new SharedResourceImplementation();
-        sharedResourceRunner = new SharedResourceRunner(sharedResourceImpl);
-        sharedResourceThread = new Thread(sharedResourceRunner, Thread.currentThread().getName()+"-SharedResourceRunner");
-        sharedResourceThread.setDaemon(true); // Allow JVM to exit, even if this one is running
-        sharedResourceThread.start();
+        sharedResourceRunner = new SharedResourceRunner(new SharedResourceImplementation());
+        sharedResourceRunner.start();
     }
   }
 
   protected final void destroy(ShutdownType shutdownType) {
     if(null != sharedResourceRunner) {
-        sharedResourceRunner.releaseAndWait();
+        sharedResourceRunner.stop();
         sharedResourceRunner = null;
     }
     if(null != sharedMap) {
@@ -153,9 +150,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
   }
 
   private WindowsGraphicsDevice defaultDevice;
-  private SharedResourceImplementation sharedResourceImpl;
   private SharedResourceRunner sharedResourceRunner;
-  private Thread sharedResourceThread;
   private HashMap<String /*connection*/, SharedResourceRunner.Resource> sharedMap;
 
   private long processAffinityChanges = 0;
@@ -397,7 +392,11 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
   final static String WGL_ARB_make_current_read = "WGL_ARB_make_current_read";
   final static String wglMakeContextCurrent = "wglMakeContextCurrent";
 
-  public final boolean getWasSharedContextCreated(AbstractGraphicsDevice device) {
+  protected final Thread getSharedResourceThread() {
+    return sharedResourceRunner.start();
+  }
+  
+  protected final boolean createSharedResource(AbstractGraphicsDevice device) {
     try {
         SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device);
         if(null!=sr) {
-- 
cgit v1.2.3