jdk/src/share/classes/java/util/concurrent/atomic/AtomicReference.java
changeset 15020 50394fa17c1b
parent 14325 622c473a21aa
child 15267 c884f548a25f
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReference.java	Thu Jan 10 15:09:45 2013 -0500
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReference.java	Thu Jan 10 21:52:38 2013 +0000
@@ -124,7 +124,7 @@
      *
      * @param expect the expected value
      * @param update the new value
-     * @return true if successful.
+     * @return true if successful
      */
     public final boolean weakCompareAndSet(V expect, V update) {
         return unsafe.compareAndSwapObject(this, valueOffset, expect, update);
@@ -136,17 +136,14 @@
      * @param newValue the new value
      * @return the previous value
      */
+    @SuppressWarnings("unchecked")
     public final V getAndSet(V newValue) {
-        while (true) {
-            V x = get();
-            if (compareAndSet(x, newValue))
-                return x;
-        }
+        return (V)unsafe.getAndSetObject(this, valueOffset, newValue);
     }
 
     /**
      * Returns the String representation of the current value.
-     * @return the String representation of the current value.
+     * @return the String representation of the current value
      */
     public String toString() {
         return String.valueOf(get());