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 long} |
20 |
|
* 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 |
52 |
|
* @param x the value to update |
53 |
|
*/ |
54 |
|
public void update(long x) { |
55 |
< |
Cell[] as; long b, v; HashCode hc; Cell a; int n; |
55 |
> |
Cell[] as; long b, v; int[] hc; Cell a; int n; |
56 |
|
if ((as = cells) != null || |
57 |
|
(b = base) < x && !casBase(b, x)) { |
58 |
|
boolean uncontended = true; |
59 |
< |
int h = (hc = threadHashCode.get()).code; |
60 |
< |
if (as == null || (n = as.length) < 1 || |
61 |
< |
(a = as[(n - 1) & h]) == null || |
59 |
> |
if ((hc = threadHashCode.get()) == null || |
60 |
> |
as == null || (n = as.length) < 1 || |
61 |
> |
(a = as[(n - 1) & hc[0]]) == null || |
62 |
|
((v = a.value) < x && !(uncontended = a.cas(v, x)))) |
63 |
|
retryUpdate(x, hc, uncontended); |
64 |
|
} |
66 |
|
|
67 |
|
/** |
68 |
|
* Returns the current maximum. The returned value is |
69 |
< |
* <em>NOT</em> an atomic snapshot: Invocation in the absence of |
69 |
> |
* <em>NOT</em> an atomic snapshot; invocation in the absence of |
70 |
|
* concurrent updates returns an accurate result, but concurrent |
71 |
|
* updates that occur while the value is being calculated might |
72 |
|
* not be incorporated. |
170 |
|
return (double)max(); |
171 |
|
} |
172 |
|
|
173 |
< |
private void writeObject(java.io.ObjectOutputStream s) |
173 |
< |
throws java.io.IOException { |
173 |
> |
private void writeObject(ObjectOutputStream s) throws IOException { |
174 |
|
s.defaultWriteObject(); |
175 |
|
s.writeLong(max()); |
176 |
|
} |
177 |
|
|
178 |
|
private void readObject(ObjectInputStream s) |
179 |
< |
throws IOException, ClassNotFoundException { |
179 |
> |
throws IOException, ClassNotFoundException { |
180 |
|
s.defaultReadObject(); |
181 |
|
busy = 0; |
182 |
|
cells = null; |