5 |
|
*/ |
6 |
|
|
7 |
|
package jsr166e; |
8 |
+ |
|
9 |
|
import java.io.IOException; |
9 |
– |
import java.io.Serializable; |
10 |
|
import java.io.ObjectInputStream; |
11 |
|
import java.io.ObjectOutputStream; |
12 |
+ |
import java.io.Serializable; |
13 |
|
|
14 |
|
/** |
15 |
|
* One or more variables that together maintain a running {@code double} |
20 |
|
* current maximum across the variables maintaining updates. |
21 |
|
* |
22 |
|
* <p>This class extends {@link Number}, but does <em>not</em> define |
23 |
< |
* methods such as {@code hashCode} and {@code compareTo} because |
24 |
< |
* instances are expected to be mutated, and so are not useful as |
25 |
< |
* collection keys. |
23 |
> |
* methods such as {@code equals}, {@code hashCode} and {@code |
24 |
> |
* compareTo} because instances are expected to be mutated, and so are |
25 |
> |
* not useful as collection keys. |
26 |
|
* |
27 |
|
* <p><em>jsr166e note: This class is targeted to be placed in |
28 |
< |
* java.util.concurrent.atomic<em> |
28 |
> |
* java.util.concurrent.atomic.</em> |
29 |
|
* |
30 |
|
* @since 1.8 |
31 |
|
* @author Doug Lea |
61 |
|
*/ |
62 |
|
public void update(double x) { |
63 |
|
long lx = Double.doubleToRawLongBits(x); |
64 |
< |
Cell[] as; long b, v; HashCode hc; Cell a; int n; |
64 |
> |
Cell[] as; long b, v; int[] hc; Cell a; int n; |
65 |
|
if ((as = cells) != null || |
66 |
|
(Double.longBitsToDouble(b = base) < x && !casBase(b, lx))) { |
67 |
|
boolean uncontended = true; |
68 |
< |
int h = (hc = threadHashCode.get()).code; |
69 |
< |
if (as == null || (n = as.length) < 1 || |
70 |
< |
(a = as[(n - 1) & h]) == null || |
68 |
> |
if ((hc = threadHashCode.get()) == null || |
69 |
> |
as == null || (n = as.length) < 1 || |
70 |
> |
(a = as[(n - 1) & hc[0]]) == null || |
71 |
|
(Double.longBitsToDouble(v = a.value) < x && |
72 |
|
!(uncontended = a.cas(v, lx)))) |
73 |
|
retryUpdate(lx, hc, uncontended); |
76 |
|
|
77 |
|
/** |
78 |
|
* Returns the current maximum. The returned value is |
79 |
< |
* <em>NOT</em> an atomic snapshot: Invocation in the absence of |
79 |
> |
* <em>NOT</em> an atomic snapshot; invocation in the absence of |
80 |
|
* concurrent updates returns an accurate result, but concurrent |
81 |
|
* updates that occur while the value is being calculated might |
82 |
|
* not be incorporated. |
158 |
|
|
159 |
|
/** |
160 |
|
* Returns the {@link #max} as a {@code long} after a |
161 |
< |
* primitive conversion. |
161 |
> |
* narrowing primitive conversion. |
162 |
|
*/ |
163 |
|
public long longValue() { |
164 |
|
return (long)max(); |
166 |
|
|
167 |
|
/** |
168 |
|
* Returns the {@link #max} as an {@code int} after a |
169 |
< |
* primitive conversion. |
169 |
> |
* narrowing primitive conversion. |
170 |
|
*/ |
171 |
|
public int intValue() { |
172 |
|
return (int)max(); |
174 |
|
|
175 |
|
/** |
176 |
|
* Returns the {@link #max} as a {@code float} |
177 |
< |
* after a primitive conversion. |
177 |
> |
* after a narrowing primitive conversion. |
178 |
|
*/ |
179 |
|
public float floatValue() { |
180 |
|
return (float)max(); |
181 |
|
} |
182 |
|
|
183 |
< |
private void writeObject(java.io.ObjectOutputStream s) |
183 |
< |
throws java.io.IOException { |
183 |
> |
private void writeObject(ObjectOutputStream s) throws IOException { |
184 |
|
s.defaultWriteObject(); |
185 |
|
s.writeDouble(max()); |
186 |
|
} |
187 |
|
|
188 |
|
private void readObject(ObjectInputStream s) |
189 |
< |
throws IOException, ClassNotFoundException { |
189 |
> |
throws IOException, ClassNotFoundException { |
190 |
|
s.defaultReadObject(); |
191 |
|
busy = 0; |
192 |
|
cells = null; |