168 public final V getAndSet(V newValue) { |
168 public final V getAndSet(V newValue) { |
169 return (V)VALUE.getAndSet(this, newValue); |
169 return (V)VALUE.getAndSet(this, newValue); |
170 } |
170 } |
171 |
171 |
172 /** |
172 /** |
173 * Atomically updates the current value with the results of |
173 * Atomically updates (with memory effects as specified by {@link |
|
174 * VarHandle#compareAndSet}) the current value with the results of |
174 * applying the given function, returning the previous value. The |
175 * applying the given function, returning the previous value. The |
175 * function should be side-effect-free, since it may be re-applied |
176 * function should be side-effect-free, since it may be re-applied |
176 * when attempted updates fail due to contention among threads. |
177 * when attempted updates fail due to contention among threads. |
177 * |
178 * |
178 * @param updateFunction a side-effect-free function |
179 * @param updateFunction a side-effect-free function |
189 haveNext = (prev == (prev = get())); |
190 haveNext = (prev == (prev = get())); |
190 } |
191 } |
191 } |
192 } |
192 |
193 |
193 /** |
194 /** |
194 * Atomically updates the current value with the results of |
195 * Atomically updates (with memory effects as specified by {@link |
|
196 * VarHandle#compareAndSet}) the current value with the results of |
195 * applying the given function, returning the updated value. The |
197 * applying the given function, returning the updated value. The |
196 * function should be side-effect-free, since it may be re-applied |
198 * function should be side-effect-free, since it may be re-applied |
197 * when attempted updates fail due to contention among threads. |
199 * when attempted updates fail due to contention among threads. |
198 * |
200 * |
199 * @param updateFunction a side-effect-free function |
201 * @param updateFunction a side-effect-free function |
210 haveNext = (prev == (prev = get())); |
212 haveNext = (prev == (prev = get())); |
211 } |
213 } |
212 } |
214 } |
213 |
215 |
214 /** |
216 /** |
215 * Atomically updates the current value with the results of |
217 * Atomically updates (with memory effects as specified by {@link |
|
218 * VarHandle#compareAndSet}) the current value with the results of |
216 * applying the given function to the current and given values, |
219 * applying the given function to the current and given values, |
217 * returning the previous value. The function should be |
220 * returning the previous value. The function should be |
218 * side-effect-free, since it may be re-applied when attempted |
221 * side-effect-free, since it may be re-applied when attempted |
219 * updates fail due to contention among threads. The function |
222 * updates fail due to contention among threads. The function is |
220 * is applied with the current value as its first argument, |
223 * applied with the current value as its first argument, and the |
221 * and the given update as the second argument. |
224 * given update as the second argument. |
222 * |
225 * |
223 * @param x the update value |
226 * @param x the update value |
224 * @param accumulatorFunction a side-effect-free function of two arguments |
227 * @param accumulatorFunction a side-effect-free function of two arguments |
225 * @return the previous value |
228 * @return the previous value |
226 * @since 1.8 |
229 * @since 1.8 |
236 haveNext = (prev == (prev = get())); |
239 haveNext = (prev == (prev = get())); |
237 } |
240 } |
238 } |
241 } |
239 |
242 |
240 /** |
243 /** |
241 * Atomically updates the current value with the results of |
244 * Atomically updates (with memory effects as specified by {@link |
|
245 * VarHandle#compareAndSet}) the current value with the results of |
242 * applying the given function to the current and given values, |
246 * applying the given function to the current and given values, |
243 * returning the updated value. The function should be |
247 * returning the updated value. The function should be |
244 * side-effect-free, since it may be re-applied when attempted |
248 * side-effect-free, since it may be re-applied when attempted |
245 * updates fail due to contention among threads. The function |
249 * updates fail due to contention among threads. The function is |
246 * is applied with the current value as its first argument, |
250 * applied with the current value as its first argument, and the |
247 * and the given update as the second argument. |
251 * given update as the second argument. |
248 * |
252 * |
249 * @param x the update value |
253 * @param x the update value |
250 * @param accumulatorFunction a side-effect-free function of two arguments |
254 * @param accumulatorFunction a side-effect-free function of two arguments |
251 * @return the updated value |
255 * @return the updated value |
252 * @since 1.8 |
256 * @since 1.8 |