jdk/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
changeset 39725 9548f8d846e9
parent 37363 329dba26ffd2
child 42322 c3474fef4fe4
equal deleted inserted replaced
39724:d935d42f6d93 39725:9548f8d846e9
    40 import java.security.AccessController;
    40 import java.security.AccessController;
    41 import java.security.PrivilegedActionException;
    41 import java.security.PrivilegedActionException;
    42 import java.security.PrivilegedExceptionAction;
    42 import java.security.PrivilegedExceptionAction;
    43 import java.util.function.LongBinaryOperator;
    43 import java.util.function.LongBinaryOperator;
    44 import java.util.function.LongUnaryOperator;
    44 import java.util.function.LongUnaryOperator;
       
    45 import jdk.internal.misc.Unsafe;
    45 import jdk.internal.reflect.CallerSensitive;
    46 import jdk.internal.reflect.CallerSensitive;
    46 import jdk.internal.reflect.Reflection;
    47 import jdk.internal.reflect.Reflection;
    47 
    48 
    48 /**
    49 /**
    49  * A reflection-based utility that enables atomic updates to
    50  * A reflection-based utility that enables atomic updates to
   151      * @since 1.6
   152      * @since 1.6
   152      */
   153      */
   153     public abstract void lazySet(T obj, long newValue);
   154     public abstract void lazySet(T obj, long newValue);
   154 
   155 
   155     /**
   156     /**
   156      * Gets the current value held in the field of the given object managed
   157      * Returns the current value held in the field of the given object
   157      * by this updater.
   158      * managed by this updater.
   158      *
   159      *
   159      * @param obj An object whose field to get
   160      * @param obj An object whose field to get
   160      * @return the current value
   161      * @return the current value
   161      */
   162      */
   162     public abstract long get(T obj);
   163     public abstract long get(T obj);
   364         } while (!compareAndSet(obj, prev, next));
   365         } while (!compareAndSet(obj, prev, next));
   365         return next;
   366         return next;
   366     }
   367     }
   367 
   368 
   368     private static final class CASUpdater<T> extends AtomicLongFieldUpdater<T> {
   369     private static final class CASUpdater<T> extends AtomicLongFieldUpdater<T> {
   369         private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
   370         private static final Unsafe U = Unsafe.getUnsafe();
   370         private final long offset;
   371         private final long offset;
   371         /**
   372         /**
   372          * if field is protected, the subclass constructing updater, else
   373          * if field is protected, the subclass constructing updater, else
   373          * the same as tclass
   374          * the same as tclass
   374          */
   375          */
   495             return getAndAdd(obj, delta) + delta;
   496             return getAndAdd(obj, delta) + delta;
   496         }
   497         }
   497     }
   498     }
   498 
   499 
   499     private static final class LockedUpdater<T> extends AtomicLongFieldUpdater<T> {
   500     private static final class LockedUpdater<T> extends AtomicLongFieldUpdater<T> {
   500         private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
   501         private static final Unsafe U = Unsafe.getUnsafe();
   501         private final long offset;
   502         private final long offset;
   502         /**
   503         /**
   503          * if field is protected, the subclass constructing updater, else
   504          * if field is protected, the subclass constructing updater, else
   504          * the same as tclass
   505          * the same as tclass
   505          */
   506          */