182 * @param expectedReference the expected value of the reference
183 * @param newMark the new value for the mark
184 * @return {@code true} if successful
185 */
186 public boolean attemptMark(V expectedReference, boolean newMark) {
187 Pair<V> current = pair;
188 return
189 expectedReference == current.reference &&
190 (newMark == current.mark ||
191 casPair(current, Pair.of(expectedReference, newMark)));
192 }
193
194 // VarHandle mechanics
195 private static final VarHandle PAIR;
196 static {
197 try {
198 MethodHandles.Lookup l = MethodHandles.lookup();
199 PAIR = l.findVarHandle(AtomicMarkableReference.class, "pair",
200 Pair.class);
201 } catch (ReflectiveOperationException e) {
202 throw new Error(e);
203 }
204 }
205
206 private boolean casPair(Pair<V> cmp, Pair<V> val) {
207 return PAIR.compareAndSet(this, cmp, val);
208 }
209 }
|
182 * @param expectedReference the expected value of the reference
183 * @param newMark the new value for the mark
184 * @return {@code true} if successful
185 */
186 public boolean attemptMark(V expectedReference, boolean newMark) {
187 Pair<V> current = pair;
188 return
189 expectedReference == current.reference &&
190 (newMark == current.mark ||
191 casPair(current, Pair.of(expectedReference, newMark)));
192 }
193
194 // VarHandle mechanics
195 private static final VarHandle PAIR;
196 static {
197 try {
198 MethodHandles.Lookup l = MethodHandles.lookup();
199 PAIR = l.findVarHandle(AtomicMarkableReference.class, "pair",
200 Pair.class);
201 } catch (ReflectiveOperationException e) {
202 throw new ExceptionInInitializerError(e);
203 }
204 }
205
206 private boolean casPair(Pair<V> cmp, Pair<V> val) {
207 return PAIR.compareAndSet(this, cmp, val);
208 }
209 }
|