ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/CopyOnWriteArrayList.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/CopyOnWriteArrayList.java (file contents):
Revision 1.55 by jsr166, Sun Sep 11 03:13:26 2005 UTC vs.
Revision 1.56 by jsr166, Wed Sep 14 22:52:49 2005 UTC

# Line 41 | Line 41 | import sun.misc.Unsafe;
41   *
42   * <p>All elements are permitted, including <tt>null</tt>.
43   *
44 + * <p>Memory consistency effects: As with other concurrent
45 + * collections, actions in a thread prior to placing an object into a
46 + * {@code CopyOnWriteArrayList}
47 + * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
48 + * actions subsequent to the access or removal of that element from
49 + * the {@code CopyOnWriteArrayList} in another thread.
50 + *
51   * <p>This class is a member of the
52   * <a href="{@docRoot}/../guide/collections/index.html">
53   * Java Collections Framework</a>.
54   *
48 * <p>
49 * Memory consistency effects: As with other concurrent collections, state
50 * changes to any object made prior to placing it into a <tt>CopyOnWriteArrayList</tt>
51 * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
52 * that element is accessed via or removed from the <tt>CopyOnWriteArrayList</tt>.
53 *
55   * @since 1.5
56   * @author Doug Lea
57   * @param <E> the type of elements held in this collection
# Line 350 | Line 351 | public class CopyOnWriteArrayList<E>
351          lock.lock();
352          try {
353              Object[] elements = getArray();
353            int len = elements.length;
354              Object oldValue = elements[index];
355  
356              if (oldValue != element) {
357 +                int len = elements.length;
358                  Object[] newElements = Arrays.copyOf(elements, len);
359                  newElements[index] = element;
360                  setArray(newElements);
361 +            } else {
362 +                // Not quite a no-op; ensures volatile write semantics
363 +                setArray(elements);
364              }
365              return (E)oldValue;
366          } finally {
# Line 1276 | Line 1280 | public class CopyOnWriteArrayList<E>
1280      }
1281  
1282      // Support for resetting lock while deserializing
1283 <    private static final Unsafe unsafe =  Unsafe.getUnsafe();
1283 >    private static final Unsafe unsafe = Unsafe.getUnsafe();
1284      private static final long lockOffset;
1285      static {
1286          try {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines