[Swift-commit] r4666 - trunk/src/org/griphyn/vdl/karajan

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Thu Jun 23 13:27:59 CDT 2011


Author: hategan
Date: 2011-06-23 13:27:59 -0500 (Thu, 23 Jun 2011)
New Revision: 4666

Modified:
   trunk/src/org/griphyn/vdl/karajan/WrapperMap.java
Log:
only lock objects when necessary

Modified: trunk/src/org/griphyn/vdl/karajan/WrapperMap.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/WrapperMap.java	2011-06-23 18:14:30 UTC (rev 4665)
+++ trunk/src/org/griphyn/vdl/karajan/WrapperMap.java	2011-06-23 18:27:59 UTC (rev 4666)
@@ -10,10 +10,10 @@
 import org.griphyn.vdl.mapping.DSHandle;
 
 public class WrapperMap {
-	private Map map;
+	private Map<DSHandle, FutureWrappers> map;
 
 	public WrapperMap() {
-		this.map = new HashMap();
+		this.map = new HashMap<DSHandle, FutureWrappers>();
 	}
 
 	public static class FutureWrappers {
@@ -21,38 +21,49 @@
 		public ArrayIndexFutureList arrayWrapper;
 	}
 
-	public synchronized void close(DSHandle handle) {
-		FutureWrappers fw = (FutureWrappers) map.get(handle);
-		if (fw != null) {
-			if (fw.nodeWrapper != null) {
-				fw.nodeWrapper.close();
-			}
-			if (fw.arrayWrapper != null) {
-				fw.arrayWrapper.close();
-			}
+	public void close(DSHandle handle) {
+	    DSHandleFutureWrapper nodeWrapper;
+	    ArrayIndexFutureList arrayWrapper;
+	    synchronized(this) {
+	        FutureWrappers fw = map.get(handle);
+	        if (fw == null) {
+	            return;
+	        }
+	        nodeWrapper = fw.nodeWrapper;
+	        arrayWrapper = fw.arrayWrapper;
+	    }
+		if (nodeWrapper != null) {
+			nodeWrapper.close();
 		}
+		if (arrayWrapper != null) {
+			arrayWrapper.close();
+		}
 	}
 
-	public synchronized boolean isClosed(DSHandle handle) {
-		FutureWrappers fw = (FutureWrappers) map.get(handle);
-		if (fw != null) {
-			if (fw.nodeWrapper != null) {
-				return fw.nodeWrapper.isClosed();
-			}
-			else if (fw.arrayWrapper != null) {
-				return fw.arrayWrapper.isClosed();
-			}
-			else {
-				return false;
-			}
+	public boolean isClosed(DSHandle handle) {
+	    DSHandleFutureWrapper nodeWrapper;
+        ArrayIndexFutureList arrayWrapper;
+        synchronized(this) {
+            FutureWrappers fw = map.get(handle);
+            if (fw == null) {
+                return false;
+            }
+            nodeWrapper = fw.nodeWrapper;
+            arrayWrapper = fw.arrayWrapper;
+        }
+		if (nodeWrapper != null) {
+			return nodeWrapper.isClosed();
 		}
+		else if (arrayWrapper != null) {
+			return arrayWrapper.isClosed();
+		}
 		else {
 			return false;
 		}
 	}
 
 	public synchronized DSHandleFutureWrapper addNodeListener(DSHandle handle) {
-		FutureWrappers fw = (FutureWrappers) map.get(handle);
+		FutureWrappers fw = map.get(handle);
 		if (fw == null) {
 			map.put(handle, fw = new FutureWrappers());
 		}
@@ -63,8 +74,8 @@
 		return fw.nodeWrapper;
 	}
 
-	public synchronized ArrayIndexFutureList addFutureListListener(DSHandle handle, Map value) {
-		FutureWrappers fw = (FutureWrappers) map.get(handle);
+	public synchronized ArrayIndexFutureList addFutureListListener(DSHandle handle, Map<?, ?> value) {
+		FutureWrappers fw = map.get(handle);
 		if (fw == null) {
 			map.put(handle, fw = new FutureWrappers());
 		}
@@ -81,13 +92,13 @@
 	}
 
 	public synchronized void markAsAvailable(DSHandle handle, Object key) {
-		FutureWrappers fw = (FutureWrappers) map.get(handle);
+		FutureWrappers fw = map.get(handle);
 		if (fw != null && fw.arrayWrapper != null) {
 			fw.arrayWrapper.addKey(key);
 		}
 	}
 
-	public Set entrySet() {
+	public Set<Map.Entry<DSHandle, FutureWrappers>> entrySet() {
 		return map.entrySet();
 	}
 }




More information about the Swift-commit mailing list