harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject Re: svn commit: r960424 - /harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/File.java
Date Tue, 06 Jul 2010 14:29:10 GMT
On 06/Jul/2010 14:56, Mark Hindess wrote:
> Regis,
> 
> This breaks the build for the IBM VME (from developerWorks).  Since they
> don't have a sun.misc.Unsafe, so the AtomicInteger can't be resolved.
> 
> Any ideas how to fix this?
> 
> Also, the luni.jar manifest says:
> 
>   java.util.concurrent;resolution:=optional,
> 
> I wonder when it becomes non-optional.  Personally, I'd say breaking
> java.io.File would be enough to make it mandatory.

:-)

To save you wondering, the imports are 'optional' when they are only
required by the tests for a module, so the new dependency in this commit
should indeed change concurrent to be a hard requirement for luni.

We use the same manifest file in the Eclipse project (containing the
impl and test together) as we do in the impl JAR, which is why we have
to accommodate the tests in the declarations.

Regards,
Tim

> In message <20100705030517.1F57223889E5@eris.apache.org>, regisxu@apache.org
> writes:
>> Author: regisxu
>> Date: Mon Jul  5 03:05:16 2010
>> New Revision: 960424
>>
>> URL: http://svn.apache.org/viewvc?rev=960424&view=rev
>> Log:
>> make File.createTempFile thread-safe to avoid to return the same file multipl
>> e times
>>
>> File.counter could be accessed by multiple threads, so use AtomicInteger to m
>> ake
>> sure each thread using different int value to create temp file.
>>
>> Modified:
>>     harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/F
>> ile.java
>>
>> Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/jav
>> a/io/File.java
>> URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/module
>> s/luni/src/main/java/java/io/File.java?rev=960424&r1=960423&r2=960424&view=di
>> ff
>> =============================================================================
>> =
>> --- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/F
>> ile.java (original)
>> +++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/F
>> ile.java Mon Jul  5 03:05:16 2010
>> @@ -24,6 +24,7 @@ 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;
>> @@ -79,7 +80,7 @@ public class File implements Serializabl
>>      public static final String pathSeparator;
>>  
>>      /* Temp file counter */
>> -    private static int counter;
>> +    private static AtomicInteger counter = new AtomicInteger(0);
>>  
>>      private static boolean caseSensitive;
>>  
>> @@ -1300,13 +1301,13 @@ public class File implements Serializabl
>>      }
>>  
>>      private static File genTempFile(String prefix, String suffix, File direc
>> tory) {
>> -        if (counter == 0) {
>> +        if (counter.get() == 0) {
>>              int newInt = new SecureRandom().nextInt();
>> -            counter = ((newInt / 65535) & 0xFFFF) + 0x2710;
>> +            counter.compareAndSet(0, ((newInt / 65535) & 0xFFFF) + 0x2710);
>>          }
>>          StringBuilder newName = new StringBuilder();
>>          newName.append(prefix);
>> -        newName.append(counter++);
>> +        newName.append(counter.getAndIncrement());
>>          newName.append(suffix);
>>          return new File(directory, newName.toString());
>>      }
>>
> 
> 
> 

Mime
View raw message