220 |
|
|
221 |
|
boolean casNext(SNode cmp, SNode val) { |
222 |
|
return cmp == next && |
223 |
< |
UNSAFE.compareAndSwapObject(this, nextOffset, cmp, val); |
223 |
> |
U.compareAndSwapObject(this, NEXT, cmp, val); |
224 |
|
} |
225 |
|
|
226 |
|
/** |
233 |
|
*/ |
234 |
|
boolean tryMatch(SNode s) { |
235 |
|
if (match == null && |
236 |
< |
UNSAFE.compareAndSwapObject(this, matchOffset, null, s)) { |
236 |
> |
U.compareAndSwapObject(this, MATCH, null, s)) { |
237 |
|
Thread w = waiter; |
238 |
|
if (w != null) { // waiters need at most one unpark |
239 |
|
waiter = null; |
248 |
|
* Tries to cancel a wait by matching node to itself. |
249 |
|
*/ |
250 |
|
void tryCancel() { |
251 |
< |
UNSAFE.compareAndSwapObject(this, matchOffset, null, this); |
251 |
> |
U.compareAndSwapObject(this, MATCH, null, this); |
252 |
|
} |
253 |
|
|
254 |
|
boolean isCancelled() { |
256 |
|
} |
257 |
|
|
258 |
|
// Unsafe mechanics |
259 |
< |
private static final sun.misc.Unsafe UNSAFE; |
260 |
< |
private static final long matchOffset; |
261 |
< |
private static final long nextOffset; |
259 |
> |
private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe(); |
260 |
> |
private static final long MATCH; |
261 |
> |
private static final long NEXT; |
262 |
|
|
263 |
|
static { |
264 |
|
try { |
265 |
< |
UNSAFE = sun.misc.Unsafe.getUnsafe(); |
266 |
< |
Class<?> k = SNode.class; |
267 |
< |
matchOffset = UNSAFE.objectFieldOffset |
268 |
< |
(k.getDeclaredField("match")); |
269 |
< |
nextOffset = UNSAFE.objectFieldOffset |
270 |
< |
(k.getDeclaredField("next")); |
265 |
> |
MATCH = U.objectFieldOffset |
266 |
> |
(SNode.class.getDeclaredField("match")); |
267 |
> |
NEXT = U.objectFieldOffset |
268 |
> |
(SNode.class.getDeclaredField("next")); |
269 |
|
} catch (ReflectiveOperationException e) { |
270 |
|
throw new Error(e); |
271 |
|
} |
277 |
|
|
278 |
|
boolean casHead(SNode h, SNode nh) { |
279 |
|
return h == head && |
280 |
< |
UNSAFE.compareAndSwapObject(this, headOffset, h, nh); |
280 |
> |
U.compareAndSwapObject(this, HEAD, h, nh); |
281 |
|
} |
282 |
|
|
283 |
|
/** |
482 |
|
} |
483 |
|
|
484 |
|
// Unsafe mechanics |
485 |
< |
private static final sun.misc.Unsafe UNSAFE; |
486 |
< |
private static final long headOffset; |
485 |
> |
private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe(); |
486 |
> |
private static final long HEAD; |
487 |
|
static { |
488 |
|
try { |
489 |
< |
UNSAFE = sun.misc.Unsafe.getUnsafe(); |
490 |
< |
Class<?> k = TransferStack.class; |
493 |
< |
headOffset = UNSAFE.objectFieldOffset |
494 |
< |
(k.getDeclaredField("head")); |
489 |
> |
HEAD = U.objectFieldOffset |
490 |
> |
(TransferStack.class.getDeclaredField("head")); |
491 |
|
} catch (ReflectiveOperationException e) { |
492 |
|
throw new Error(e); |
493 |
|
} |
519 |
|
|
520 |
|
boolean casNext(QNode cmp, QNode val) { |
521 |
|
return next == cmp && |
522 |
< |
UNSAFE.compareAndSwapObject(this, nextOffset, cmp, val); |
522 |
> |
U.compareAndSwapObject(this, NEXT, cmp, val); |
523 |
|
} |
524 |
|
|
525 |
|
boolean casItem(Object cmp, Object val) { |
526 |
|
return item == cmp && |
527 |
< |
UNSAFE.compareAndSwapObject(this, itemOffset, cmp, val); |
527 |
> |
U.compareAndSwapObject(this, ITEM, cmp, val); |
528 |
|
} |
529 |
|
|
530 |
|
/** |
531 |
|
* Tries to cancel by CAS'ing ref to this as item. |
532 |
|
*/ |
533 |
|
void tryCancel(Object cmp) { |
534 |
< |
UNSAFE.compareAndSwapObject(this, itemOffset, cmp, this); |
534 |
> |
U.compareAndSwapObject(this, ITEM, cmp, this); |
535 |
|
} |
536 |
|
|
537 |
|
boolean isCancelled() { |
548 |
|
} |
549 |
|
|
550 |
|
// Unsafe mechanics |
551 |
< |
private static final sun.misc.Unsafe UNSAFE; |
552 |
< |
private static final long itemOffset; |
553 |
< |
private static final long nextOffset; |
551 |
> |
private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe(); |
552 |
> |
private static final long ITEM; |
553 |
> |
private static final long NEXT; |
554 |
|
|
555 |
|
static { |
556 |
|
try { |
557 |
< |
UNSAFE = sun.misc.Unsafe.getUnsafe(); |
558 |
< |
Class<?> k = QNode.class; |
559 |
< |
itemOffset = UNSAFE.objectFieldOffset |
560 |
< |
(k.getDeclaredField("item")); |
561 |
< |
nextOffset = UNSAFE.objectFieldOffset |
566 |
< |
(k.getDeclaredField("next")); |
567 |
< |
} catch (Exception e) { |
557 |
> |
ITEM = U.objectFieldOffset |
558 |
> |
(QNode.class.getDeclaredField("item")); |
559 |
> |
NEXT = U.objectFieldOffset |
560 |
> |
(QNode.class.getDeclaredField("next")); |
561 |
> |
} catch (ReflectiveOperationException e) { |
562 |
|
throw new Error(e); |
563 |
|
} |
564 |
|
} |
587 |
|
*/ |
588 |
|
void advanceHead(QNode h, QNode nh) { |
589 |
|
if (h == head && |
590 |
< |
UNSAFE.compareAndSwapObject(this, headOffset, h, nh)) |
590 |
> |
U.compareAndSwapObject(this, HEAD, h, nh)) |
591 |
|
h.next = h; // forget old next |
592 |
|
} |
593 |
|
|
596 |
|
*/ |
597 |
|
void advanceTail(QNode t, QNode nt) { |
598 |
|
if (tail == t) |
599 |
< |
UNSAFE.compareAndSwapObject(this, tailOffset, t, nt); |
599 |
> |
U.compareAndSwapObject(this, TAIL, t, nt); |
600 |
|
} |
601 |
|
|
602 |
|
/** |
604 |
|
*/ |
605 |
|
boolean casCleanMe(QNode cmp, QNode val) { |
606 |
|
return cleanMe == cmp && |
607 |
< |
UNSAFE.compareAndSwapObject(this, cleanMeOffset, cmp, val); |
607 |
> |
U.compareAndSwapObject(this, CLEANME, cmp, val); |
608 |
|
} |
609 |
|
|
610 |
|
/** |
790 |
|
} |
791 |
|
} |
792 |
|
|
793 |
< |
private static final sun.misc.Unsafe UNSAFE; |
794 |
< |
private static final long headOffset; |
795 |
< |
private static final long tailOffset; |
796 |
< |
private static final long cleanMeOffset; |
793 |
> |
private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe(); |
794 |
> |
private static final long HEAD; |
795 |
> |
private static final long TAIL; |
796 |
> |
private static final long CLEANME; |
797 |
|
static { |
798 |
|
try { |
799 |
< |
UNSAFE = sun.misc.Unsafe.getUnsafe(); |
800 |
< |
Class<?> k = TransferQueue.class; |
801 |
< |
headOffset = UNSAFE.objectFieldOffset |
802 |
< |
(k.getDeclaredField("head")); |
803 |
< |
tailOffset = UNSAFE.objectFieldOffset |
804 |
< |
(k.getDeclaredField("tail")); |
811 |
< |
cleanMeOffset = UNSAFE.objectFieldOffset |
812 |
< |
(k.getDeclaredField("cleanMe")); |
799 |
> |
HEAD = U.objectFieldOffset |
800 |
> |
(TransferQueue.class.getDeclaredField("head")); |
801 |
> |
TAIL = U.objectFieldOffset |
802 |
> |
(TransferQueue.class.getDeclaredField("tail")); |
803 |
> |
CLEANME = U.objectFieldOffset |
804 |
> |
(TransferQueue.class.getDeclaredField("cleanMe")); |
805 |
|
} catch (ReflectiveOperationException e) { |
806 |
|
throw new Error(e); |
807 |
|
} |