Esempio n. 1
0
        /// <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 long UpdateAndGet(LongUnaryOperator updateFunction)
        {
            long prev, next;

            do
            {
                prev = Get();
                next = updateFunction.ApplyAsLong(prev);
            } while (!CompareAndSet(prev, next));
            return(next);
        }
Esempio n. 2
0
        /// <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 long GetAndUpdate(T obj, LongUnaryOperator updateFunction)
        {
            long prev, next;

            do
            {
                prev = Get(obj);
                next = updateFunction.ApplyAsLong(prev);
            } while (!CompareAndSet(obj, prev, next));
            return(prev);
        }
Esempio n. 3
0
        /// <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 long UpdateAndGet(int i, LongUnaryOperator updateFunction)
        {
            long offset = CheckedByteOffset(i);
            long prev, next;

            do
            {
                prev = GetRaw(offset);
                next = updateFunction.ApplyAsLong(prev);
            } while (!CompareAndSetRaw(offset, prev, next));
            return(next);
        }
Esempio n. 4
0
 public long updateAndGet(LongUnaryOperator arg0)
 {
     return Instance.CallMethod<long>("updateAndGet", "(Ljava/util/function/LongUnaryOperator;)J", arg0);
 }
Esempio n. 5
0
 public long getAndUpdate(LongUnaryOperator arg0)
 {
     return Instance.CallMethod<long>("getAndUpdate", "(Ljava/util/function/LongUnaryOperator;)J", arg0);
 }