1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.util.internal;
17
18 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
19 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
20
21 final class AtomicFieldUpdaterUtil {
22
23 private static final boolean AVAILABLE;
24
25 static final class Node {
26 volatile Node next;
27 Node() {
28 super();
29 }
30 }
31
32 static {
33 boolean available = false;
34 try {
35 AtomicReferenceFieldUpdater<Node, Node> tmp =
36 AtomicReferenceFieldUpdater.newUpdater(
37 Node.class, Node.class, "next");
38
39
40 Node testNode = new Node();
41 tmp.set(testNode, testNode);
42 if (testNode.next != testNode) {
43
44 throw new Exception();
45 }
46 available = true;
47 } catch (Throwable t) {
48
49 }
50 AVAILABLE = available;
51 }
52
53 static <T, V> AtomicReferenceFieldUpdater<T, V> newRefUpdater(Class<T> tclass, Class<V> vclass, String fieldName) {
54 if (AVAILABLE) {
55 return AtomicReferenceFieldUpdater.newUpdater(tclass, vclass, fieldName);
56 } else {
57 return null;
58 }
59 }
60
61 static <T> AtomicIntegerFieldUpdater<T> newIntUpdater(Class<T> tclass, String fieldName) {
62 if (AVAILABLE) {
63 return AtomicIntegerFieldUpdater.newUpdater(tclass, fieldName);
64 } else {
65 return null;
66 }
67 }
68
69 static boolean isAvailable() {
70 return AVAILABLE;
71 }
72
73 private AtomicFieldUpdaterUtil() {
74
75 }
76 }