ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/AtomicLinkedNode.java
Revision: 1.3
Committed: Mon Aug 4 12:46:34 2003 UTC (20 years, 10 months ago) by dl
Branch: MAIN
Changes since 1.2: +2 -2 lines
Log Message:
Pass 1 of 1.5.0 changes

File Contents

# User Rev Content
1 dl 1.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 dl 1.2 * @since 1.5
14     * @author Doug Lea
15 dl 1.1 */
16    
17     final class AtomicLinkedNode {
18     private volatile Object item;
19     private volatile AtomicLinkedNode next;
20    
21 dl 1.2 private static final AtomicReferenceFieldUpdater<AtomicLinkedNode, AtomicLinkedNode> nextUpdater =
22 dl 1.3 new AtomicReferenceFieldUpdater<AtomicLinkedNode, AtomicLinkedNode>(AtomicLinkedNode.class, AtomicLinkedNode.class, "next");
23 dl 1.2 private static final AtomicReferenceFieldUpdater<AtomicLinkedNode, Object> itemUpdater
24 dl 1.3 = new AtomicReferenceFieldUpdater<AtomicLinkedNode, Object>(AtomicLinkedNode.class, Object.class, "item");
25 dl 1.1
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     }