[libbluray-devel] BDJ: make sure BDJActionManager is always created in right context.

hpi1 git at videolan.org
Thu Mar 27 14:59:04 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Mar 27 14:44:11 2014 +0200| [1209cb5dfaea05bb1cdf1cc60e3a283f7316d263] | committer: hpi1

BDJ: make sure BDJActionManager is always created in right context.

If ActionManager was closed, and Xlet posted new action, new ActionManager was created in Xlet context.

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=1209cb5dfaea05bb1cdf1cc60e3a283f7316d263
---

 .../bdj/java/org/videolan/BDJActionManager.java    |   24 ++++++++++++--------
 src/libbluray/bdj/java/org/videolan/Libbluray.java |    4 ++--
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/libbluray/bdj/java/org/videolan/BDJActionManager.java b/src/libbluray/bdj/java/org/videolan/BDJActionManager.java
index b42d363..fc2d4e7 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJActionManager.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJActionManager.java
@@ -19,11 +19,15 @@
 package org.videolan;
 
 public class BDJActionManager {
-    public static BDJActionManager getInstance() {
-        synchronized (BDJActionManager.class) {
-            if (instance == null)
-                instance = new BDJActionManager();
+    protected static BDJActionManager createInstance() {
+        if (running) {
+            System.err.println("BDJActionManager: manager already running! " + Logger.dumpStack());
+            return;
         }
+        instance = new BDJActionManager();
+    }
+
+    public static BDJActionManager getInstance() {
         return instance;
     }
 
@@ -31,12 +35,13 @@ public class BDJActionManager {
         commandQueue = new BDJActionQueue();
     }
 
-    protected void finalize() throws Throwable {
-        commandQueue.shutdown();
-        synchronized (BDJActionManager.class) {
-            instance = null;
+    protected static void shutdown() {
+        try {
+            instance.commandQueue.shutdown();
+        } catch (Throwable t) {
+        } finally {
+            running = false;
         }
-        super.finalize();
     }
 
     public void putCommand(BDJAction action) {
@@ -46,4 +51,5 @@ public class BDJActionManager {
     private BDJActionQueue commandQueue;
 
     private static BDJActionManager instance = null;
+    private static boolean running = false;
 }
diff --git a/src/libbluray/bdj/java/org/videolan/Libbluray.java b/src/libbluray/bdj/java/org/videolan/Libbluray.java
index 92adaff..b2684ab 100644
--- a/src/libbluray/bdj/java/org/videolan/Libbluray.java
+++ b/src/libbluray/bdj/java/org/videolan/Libbluray.java
@@ -47,7 +47,7 @@ public class Libbluray {
             Libbluray.nativePointer = nativePointer;
             DiscManager.getDiscManager().setCurrentDisc(discID);
 
-            BDJActionManager.getInstance();
+            BDJActionManager.createInstance();
 
             Vector prefix = new Vector();
             prefix.add("org.videolan");
@@ -129,7 +129,7 @@ public class Libbluray {
     public static void shutdown() {
         try {
             BDJLoader.shutdown();
-            BDJActionManager.getInstance().finalize();
+            BDJActionManager.shutdown();
             MountManager.unmountAll();
             GUIManager.shutdown();
             BDToolkit.shutdownDisc();



More information about the libbluray-devel mailing list