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 }
28
29 static {
30 boolean available = false;
31 try {
32 AtomicReferenceFieldUpdater<Node, Node> tmp =
33 AtomicReferenceFieldUpdater.newUpdater(
34 Node.class, Node.class, "next");
35
36
37 Node testNode = new Node();
38 tmp.set(testNode, testNode);
39 if (testNode.next != testNode) {
40
41 throw new Exception();
42 }
43 available = true;
44 } catch (Throwable t) {
45
46 }
47 AVAILABLE = available;
48 }
49
50 static <T, V> AtomicReferenceFieldUpdater<T, V> newRefUpdater(Class<T> tclass, Class<V> vclass, String fieldName) {
51 if (AVAILABLE) {
52 return AtomicReferenceFieldUpdater.newUpdater(tclass, vclass, fieldName);
53 } else {
54 return null;
55 }
56 }
57
58 static <T> AtomicIntegerFieldUpdater<T> newIntUpdater(Class<T> tclass, String fieldName) {
59 if (AVAILABLE) {
60 return AtomicIntegerFieldUpdater.newUpdater(tclass, fieldName);
61 } else {
62 return null;
63 }
64 }
65
66 static boolean isAvailable() {
67 return AVAILABLE;
68 }
69
70 private AtomicFieldUpdaterUtil() {
71
72 }
73 }