[libbluray-devel] BD-J: use dedicated locks for global object creation/destruction

hpi1 git at videolan.org
Wed Mar 23 14:12:47 CET 2016


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Mar 23 13:43:10 2016 +0200| [47812009532738044d6a3d22cdcf1cb99825ef96] | committer: hpi1

BD-J: use dedicated locks for global object creation/destruction

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

 .../bdj/java/javax/tv/service/SIManagerImpl.java   |    7 +++++--
 .../bdj/java/org/bluray/bdplus/Status.java         |    7 +++++--
 .../bdj/java/org/bluray/ti/DiscManager.java        |   13 +++++++++----
 .../bdj/java/org/dvb/event/EventManager.java       |    7 +++++--
 .../bdj/java/org/dvb/io/ixc/IxcRegistry.java       |    6 ++++--
 .../java/org/dvb/user/UserPreferenceManager.java   |    4 +++-
 .../bdj/java/org/videolan/BDJAppsDatabase.java     |    5 ++++-
 .../bdj/java/org/videolan/GUIManager.java          |   20 ++++++++++++--------
 8 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/src/libbluray/bdj/java/javax/tv/service/SIManagerImpl.java b/src/libbluray/bdj/java/javax/tv/service/SIManagerImpl.java
index f9d4a32..3ab923d 100644
--- a/src/libbluray/bdj/java/javax/tv/service/SIManagerImpl.java
+++ b/src/libbluray/bdj/java/javax/tv/service/SIManagerImpl.java
@@ -34,8 +34,11 @@ import org.bluray.ti.TitleImpl;
 import org.videolan.Libbluray;
 
 public class SIManagerImpl extends SIManager {
+
+    private static final Object instanceLock = new Object();
+
     public static SIManager createInstance() {
-        synchronized (SIManagerImpl.class) {
+        synchronized (instanceLock) {
             if (instance == null)
                 instance = new SIManagerImpl();
             return instance;
@@ -43,7 +46,7 @@ public class SIManagerImpl extends SIManager {
     }
 
     public static void shutdown() {
-        synchronized (SIManagerImpl.class) {
+        synchronized (instanceLock) {
             instance = null;
         }
     }
diff --git a/src/libbluray/bdj/java/org/bluray/bdplus/Status.java b/src/libbluray/bdj/java/org/bluray/bdplus/Status.java
index b897b3e..0d473b0 100644
--- a/src/libbluray/bdj/java/org/bluray/bdplus/Status.java
+++ b/src/libbluray/bdj/java/org/bluray/bdplus/Status.java
@@ -24,8 +24,11 @@ import org.videolan.Libbluray;
 import org.videolan.Logger;
 
 public class Status {
+
+    private static final Object instanceLock = new Object();
+
     public static Status getInstance() {
-        synchronized (Status.class) {
+        synchronized (instanceLock) {
             if (instance == null)
                 instance = new Status();
             return instance;
@@ -34,7 +37,7 @@ public class Status {
 
     public static void shutdown() {
         Status s;
-        synchronized (Status.class) {
+        synchronized (instanceLock) {
             s = instance;
             instance = null;
         }
diff --git a/src/libbluray/bdj/java/org/bluray/ti/DiscManager.java b/src/libbluray/bdj/java/org/bluray/ti/DiscManager.java
index c43f472..02ea654 100644
--- a/src/libbluray/bdj/java/org/bluray/ti/DiscManager.java
+++ b/src/libbluray/bdj/java/org/bluray/ti/DiscManager.java
@@ -22,10 +22,15 @@ package org.bluray.ti;
 import java.util.LinkedList;
 
 public class DiscManager {
-    public static synchronized DiscManager getDiscManager() {
-        if (instance == null)
-            instance = new DiscManager();
-        return instance;
+
+    private static final Object instanceLock = new Object();
+
+    public static DiscManager getDiscManager() {
+        synchronized (instanceLock) {
+            if (instance == null)
+                instance = new DiscManager();
+            return instance;
+        }
     }
 
     public void expectNextDisc(String[] discIds) {
diff --git a/src/libbluray/bdj/java/org/dvb/event/EventManager.java b/src/libbluray/bdj/java/org/dvb/event/EventManager.java
index 844b72d..9b7206e 100644
--- a/src/libbluray/bdj/java/org/dvb/event/EventManager.java
+++ b/src/libbluray/bdj/java/org/dvb/event/EventManager.java
@@ -36,8 +36,11 @@ import org.videolan.GUIManager;
 import org.videolan.Logger;
 
 public class EventManager implements ResourceServer {
+
+    private static final Object instanceLock = new Object();
+
     public static EventManager getInstance() {
-        synchronized (EventManager.class) {
+        synchronized (instanceLock) {
             if (instance == null)
                 instance = new EventManager();
             return instance;
@@ -46,7 +49,7 @@ public class EventManager implements ResourceServer {
 
     public static void shutdown() {
         EventManager e;
-        synchronized (EventManager.class) {
+        synchronized (instanceLock) {
             e = instance;
             instance = null;
         }
diff --git a/src/libbluray/bdj/java/org/dvb/io/ixc/IxcRegistry.java b/src/libbluray/bdj/java/org/dvb/io/ixc/IxcRegistry.java
index 8ad8e51..6054849 100644
--- a/src/libbluray/bdj/java/org/dvb/io/ixc/IxcRegistry.java
+++ b/src/libbluray/bdj/java/org/dvb/io/ixc/IxcRegistry.java
@@ -30,10 +30,12 @@ import org.videolan.IxcRegistryImpl;
 
 public class IxcRegistry {
 
+    private static final Object instanceLock = new Object();
+
     private static IxcRegistryImpl registry = null;
 
     private static IxcRegistryImpl getIxcRegistry() {
-        synchronized (IxcRegistry.class) {
+        synchronized (instanceLock) {
             if (registry == null) {
                 registry = new IxcRegistryImpl();
             }
@@ -43,7 +45,7 @@ public class IxcRegistry {
 
     public static void shutdown() {
         IxcRegistryImpl r;
-        synchronized (IxcRegistry.class) {
+        synchronized (instanceLock) {
             r = registry;
             registry = null;
         }
diff --git a/src/libbluray/bdj/java/org/dvb/user/UserPreferenceManager.java b/src/libbluray/bdj/java/org/dvb/user/UserPreferenceManager.java
index af86b4e..1367d1d 100644
--- a/src/libbluray/bdj/java/org/dvb/user/UserPreferenceManager.java
+++ b/src/libbluray/bdj/java/org/dvb/user/UserPreferenceManager.java
@@ -27,8 +27,10 @@ public class UserPreferenceManager {
     private UserPreferenceManager() {
     }
 
+    private static final Object instanceLock = new Object();
+
     public static UserPreferenceManager getInstance() {
-        synchronized (UserPreferenceManager.class) {
+        synchronized (instanceLock) {
             if (instance == null)
                 instance = new UserPreferenceManager();
             return instance;
diff --git a/src/libbluray/bdj/java/org/videolan/BDJAppsDatabase.java b/src/libbluray/bdj/java/org/videolan/BDJAppsDatabase.java
index 8fea525..7a22dba 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJAppsDatabase.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJAppsDatabase.java
@@ -31,8 +31,11 @@ import org.videolan.bdjo.AppEntry;
 import org.videolan.bdjo.Bdjo;
 
 public class BDJAppsDatabase extends AppsDatabase {
+
+    private static final Object instanceLock = new Object();
+
     static public AppsDatabase getAppsDatabase() {
-        synchronized (BDJAppsDatabase.class) {
+        synchronized (instanceLock) {
             if (instance == null)
                 instance = new BDJAppsDatabase();
             return instance;
diff --git a/src/libbluray/bdj/java/org/videolan/GUIManager.java b/src/libbluray/bdj/java/org/videolan/GUIManager.java
index 0c7f578..27c2826 100644
--- a/src/libbluray/bdj/java/org/videolan/GUIManager.java
+++ b/src/libbluray/bdj/java/org/videolan/GUIManager.java
@@ -30,14 +30,18 @@ public class GUIManager extends BDRootWindow {
     private GUIManager() {
     }
 
-    public static synchronized GUIManager createInstance() {
-        if (instance == null) {
-            instance = new GUIManager();
-        } else {
-            instance.clearOverlay();
-            instance.setDefaultFont(null);
+    private static final Object instanceLock = new Object();
+
+    public static GUIManager createInstance() {
+        synchronized (instanceLock) {
+            if (instance == null) {
+                instance = new GUIManager();
+            } else {
+                instance.clearOverlay();
+                instance.setDefaultFont(null);
+            }
+            return instance;
         }
-        return instance;
     }
 
     public static synchronized GUIManager getInstance() {
@@ -69,7 +73,7 @@ public class GUIManager extends BDRootWindow {
     }
 
     protected static void shutdown() throws Throwable {
-        synchronized (GUIManager.class) {
+        synchronized (instanceLock) {
             if (instance != null) {
                 instance.setVisible(false);
                 instance.removeAll();



More information about the libbluray-devel mailing list