harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r961242 - /harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/File.java
Date Wed, 07 Jul 2010 04:42:43 GMT
Author: regisxu
Date: Wed Jul  7 04:42:42 2010
New Revision: 961242

URL: http://svn.apache.org/viewvc?rev=961242&view=rev
Log:
Because IBM VME doesn't support AtomicInteger, using 'synchronized' instead.
And also avoid temp file name confilicts when multi-VMs running concurrently.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/File.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/File.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/File.java?rev=961242&r1=961241&r2=961242&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/File.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/File.java Wed
Jul  7 04:42:42 2010
@@ -24,7 +24,6 @@ import java.security.AccessController;
 import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.harmony.luni.internal.io.FileCanonPathCache;
 import org.apache.harmony.luni.util.DeleteOnExit;
@@ -80,7 +79,14 @@ public class File implements Serializabl
     public static final String pathSeparator;
 
     /* Temp file counter */
-    private static AtomicInteger counter = new AtomicInteger(0);
+    private static int counter = 0;
+
+    /* identify for differnt VM processes */
+    private static int counterBase = 0;
+
+    private static class TempFileLocker {};
+
+    private static TempFileLocker tempFileLocker = new TempFileLocker();
 
     private static boolean caseSensitive;
 
@@ -1301,13 +1307,20 @@ public class File implements Serializabl
     }
 
     private static File genTempFile(String prefix, String suffix, File directory) {
-        if (counter.get() == 0) {
-            int newInt = new SecureRandom().nextInt();
-            counter.compareAndSet(0, ((newInt / 65535) & 0xFFFF) + 0x2710);
+        int identify = 0;
+        synchronized (tempFileLocker) {
+            if (counter == 0) {
+                int newInt = new SecureRandom().nextInt();
+                counter = ((newInt / 65535) & 0xFFFF) + 0x2710;
+                counterBase = counter;
+            }
+            identify = counter++;
         }
+
         StringBuilder newName = new StringBuilder();
         newName.append(prefix);
-        newName.append(counter.getAndIncrement());
+        newName.append(counterBase);
+        newName.append(identify);
         newName.append(suffix);
         return new File(directory, newName.toString());
     }



Mime
View raw message