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 an initially zero |
63 |
|
* @param x the value to add |
64 |
|
*/ |
65 |
|
public void add(double x) { |
66 |
< |
Cell[] as; long b, v; HashCode hc; Cell a; int n; |
66 |
> |
Cell[] as; long b, v; int[] hc; Cell a; int n; |
67 |
|
if ((as = cells) != null || |
68 |
|
!casBase(b = base, |
69 |
|
Double.doubleToRawLongBits |
70 |
|
(Double.longBitsToDouble(b) + x))) { |
71 |
|
boolean uncontended = true; |
72 |
< |
int h = (hc = threadHashCode.get()).code; |
73 |
< |
if (as == null || (n = as.length) < 1 || |
74 |
< |
(a = as[(n - 1) & h]) == null || |
72 |
> |
if ((hc = threadHashCode.get()) == null || |
73 |
> |
as == null || (n = as.length) < 1 || |
74 |
> |
(a = as[(n - 1) & hc[0]]) == null || |
75 |
|
!(uncontended = a.cas(v = a.value, |
76 |
|
Double.doubleToRawLongBits |
77 |
|
(Double.longBitsToDouble(v) + x)))) |
81 |
|
|
82 |
|
/** |
83 |
|
* Returns the current sum. The returned value is <em>NOT</em> an |
84 |
< |
* atomic snapshot: invocation in the absence of concurrent |
84 |
> |
* atomic snapshot; invocation in the absence of concurrent |
85 |
|
* updates returns an accurate result, but concurrent updates that |
86 |
|
* occur while the sum is being calculated might not be |
87 |
< |
* incorporated. Also, because double-precision arithmetic is not |
87 |
> |
* incorporated. Also, because floating-point arithmetic is not |
88 |
|
* strictly associative, the returned result need not be identical |
89 |
|
* to the value that would be obtained in a sequential series of |
90 |
|
* updates to a single variable. |
185 |
|
return (float)sum(); |
186 |
|
} |
187 |
|
|
188 |
< |
private void writeObject(java.io.ObjectOutputStream s) |
188 |
< |
throws java.io.IOException { |
188 |
> |
private void writeObject(ObjectOutputStream s) throws IOException { |
189 |
|
s.defaultWriteObject(); |
190 |
|
s.writeDouble(sum()); |
191 |
|
} |
192 |
|
|
193 |
|
private void readObject(ObjectInputStream s) |
194 |
< |
throws IOException, ClassNotFoundException { |
194 |
> |
throws IOException, ClassNotFoundException { |
195 |
|
s.defaultReadObject(); |
196 |
|
busy = 0; |
197 |
|
cells = null; |