/// <summary> /// Atomically updates the current value with the results of /// applying the given function, returning the updated value. The /// function should be side-effect-free, since it may be re-applied /// when attempted updates fail due to contention among threads. /// </summary> /// <param name="updateFunction"> a side-effect-free function </param> /// <returns> the updated value /// @since 1.8 </returns> public int UpdateAndGet(IntUnaryOperator updateFunction) { int prev, next; do { prev = Get(); next = updateFunction.ApplyAsInt(prev); } while (!CompareAndSet(prev, next)); return(next); }
/// <summary> /// Atomically updates the field of the given object managed by this updater /// with the results of applying the given function, returning the previous /// value. The function should be side-effect-free, since it may be /// re-applied when attempted updates fail due to contention among threads. /// </summary> /// <param name="obj"> An object whose field to get and set </param> /// <param name="updateFunction"> a side-effect-free function </param> /// <returns> the previous value /// @since 1.8 </returns> public int GetAndUpdate(T obj, IntUnaryOperator updateFunction) { int prev, next; do { prev = Get(obj); next = updateFunction.ApplyAsInt(prev); } while (!CompareAndSet(obj, prev, next)); return(prev); }
/// <summary> /// Atomically updates the element at index {@code i} with the results /// of applying the given function, returning the updated value. The /// function should be side-effect-free, since it may be re-applied /// when attempted updates fail due to contention among threads. /// </summary> /// <param name="i"> the index </param> /// <param name="updateFunction"> a side-effect-free function </param> /// <returns> the updated value /// @since 1.8 </returns> public int UpdateAndGet(int i, IntUnaryOperator updateFunction) { long offset = CheckedByteOffset(i); int prev, next; do { prev = GetRaw(offset); next = updateFunction.ApplyAsInt(prev); } while (!CompareAndSetRaw(offset, prev, next)); return(next); }
public int updateAndGet(int arg0, IntUnaryOperator arg1) { return Instance.CallMethod<int>("updateAndGet", "(ILjava/util/function/IntUnaryOperator;)I", arg0, arg1); }
public int getAndUpdate(int arg0, IntUnaryOperator arg1) { return Instance.CallMethod<int>("getAndUpdate", "(ILjava/util/function/IntUnaryOperator;)I", arg0, arg1); }