[libbluray-devel] bdj: fix synchronization problems in MountManager
hpi1
git at videolan.org
Sat Mar 8 10:34:56 CET 2014
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sat Mar 8 11:29:32 2014 +0200| [c1e23148571324ae5d7b5fdc83c47e45ef5486a4] | committer: hpi1
bdj: fix synchronization problems in MountManager
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=c1e23148571324ae5d7b5fdc83c47e45ef5486a4
---
.../bdj/java/org/videolan/MountManager.java | 42 +++++++++++++++-----
1 file changed, 33 insertions(+), 9 deletions(-)
diff --git a/src/libbluray/bdj/java/org/videolan/MountManager.java b/src/libbluray/bdj/java/org/videolan/MountManager.java
index e88a263..ed91f6b 100644
--- a/src/libbluray/bdj/java/org/videolan/MountManager.java
+++ b/src/libbluray/bdj/java/org/videolan/MountManager.java
@@ -48,6 +48,7 @@ public class MountManager {
if (jarStr == null)
throw new IllegalArgumentException();
+ synchronized (mountPoints) {
String oldPath = getMount(jarId);
if (oldPath != null) {
logger.error("JAR " + jarId + " already mounted");
@@ -107,31 +108,54 @@ public class MountManager {
mountPoints.put(new Integer(jarId), tmpDir);
return tmpDir.getAbsolutePath();
+ }
}
public static void unmount(int jarId) {
logger.info("Unmounting JAR: " + jarId);
+
Integer id = new Integer(jarId);
- File mountPoint = (File)mountPoints.get(id);
+ File mountPoint;
+
+ synchronized (mountPoints) {
+ mountPoint = (File)mountPoints.remove(id);
+ }
if (mountPoint != null) {
recursiveDelete(mountPoint);
- mountPoints.remove(id);
+ } else {
+ logger.info("JAR " + jarId + " not mounted");
}
}
public static void unmountAll() {
- Iterator iterator = mountPoints.keySet().iterator();
- while (iterator.hasNext())
- unmount(((Integer)iterator.next()).intValue());
+ logger.info("Unmounting all JARs");
+
+ Object[] dirs;
+
+ synchronized (mountPoints) {
+ dirs = mountPoints.values().toArray();
+ mountPoints.clear();
+ }
+ if (dirs != null) {
+ for (int i = 0; i < dirs.length; i++) {
+ recursiveDelete((File)dirs[i]);
+ }
+ }
}
public static String getMount(int jarId) {
Integer id = new Integer(jarId);
- if (mountPoints.containsKey(id)) {
- return ((File)mountPoints.get(id)).getAbsolutePath();
+ File mountPoint;
+
+ synchronized (mountPoints) {
+ mountPoint = (File)mountPoints.get(id);
+ }
+ if (mountPoint != null) {
+ return mountPoint.getAbsolutePath();
} else {
- return null;
+ logger.info("JAR " + jarId + " not mounted");
}
+ return null;
}
private static String jarIdToString(int jarId) {
@@ -154,6 +178,6 @@ public class MountManager {
dir.delete();
}
- private static Map mountPoints = Collections.synchronizedMap(new HashMap());
+ private static Map mountPoints = new HashMap();
private static final Logger logger = Logger.getLogger(MountManager.class.getName());
}
More information about the libbluray-devel
mailing list