1 |
/* |
2 |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
* Expert Group and released to the public domain. Use, modify, and |
4 |
* redistribute this code in any way without acknowledgement. |
5 |
*/ |
6 |
|
7 |
package java.util.concurrent; |
8 |
import java.util.concurrent.atomic.*; |
9 |
|
10 |
/** |
11 |
* A linked list node supporting atomic operations on both item and |
12 |
* next fields, Used by non-blocking linked-list based classes. |
13 |
* @since 1.5 |
14 |
* @author Doug Lea |
15 |
*/ |
16 |
|
17 |
final class AtomicLinkedNode { |
18 |
private volatile Object item; |
19 |
private volatile AtomicLinkedNode next; |
20 |
|
21 |
private static final AtomicReferenceFieldUpdater<AtomicLinkedNode, AtomicLinkedNode> nextUpdater = |
22 |
new AtomicReferenceFieldUpdater<AtomicLinkedNode, AtomicLinkedNode>(AtomicLinkedNode.class, AtomicLinkedNode.class, "next"); |
23 |
private static final AtomicReferenceFieldUpdater<AtomicLinkedNode, Object> itemUpdater |
24 |
= new AtomicReferenceFieldUpdater<AtomicLinkedNode, Object>(AtomicLinkedNode.class, Object.class, "item"); |
25 |
|
26 |
AtomicLinkedNode(Object x) { item = x; } |
27 |
|
28 |
AtomicLinkedNode(Object x, AtomicLinkedNode n) { item = x; next = n; } |
29 |
|
30 |
Object getItem() { |
31 |
return item; |
32 |
} |
33 |
|
34 |
boolean casItem(Object cmp, Object val) { |
35 |
return itemUpdater.compareAndSet(this, cmp, val); |
36 |
} |
37 |
|
38 |
void setItem(Object val) { |
39 |
itemUpdater.set(this, val); |
40 |
} |
41 |
|
42 |
AtomicLinkedNode getNext() { |
43 |
return next; |
44 |
} |
45 |
|
46 |
boolean casNext(AtomicLinkedNode cmp, AtomicLinkedNode val) { |
47 |
return nextUpdater.compareAndSet(this, cmp, val); |
48 |
} |
49 |
|
50 |
void setNext(AtomicLinkedNode val) { |
51 |
nextUpdater.set(this, val); |
52 |
} |
53 |
|
54 |
} |