Go to the documentation of this file. 1 package com.cliffc.aa.util;
3 import java.io.Serializable;
4 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
6 import sun.misc.Unsafe;
39 public void set(
long x ) {
40 CAT newcat =
new CAT(
null,4,x);
86 private static AtomicReferenceFieldUpdater<ConcurrentAutoTable,CAT>
_catUpdater =
91 private static int hash() {
93 int h = System.identityHashCode(Thread.currentThread());
98 private static class CAT implements Serializable {
105 assert i >= 0 && i < ary.length;
108 private static boolean CAS(
long[] A,
int idx,
long old,
long nnn ) {
120 private final long[]
_t;
133 final int idx =
hash & (t.length-1);
136 final boolean ok =
CAS( t, idx, old, old+x );
142 if(
CAS( t, idx, old, old+x ) )
break;
146 if( t.length >= 1024*1024 )
return old;
154 if( master.
_cat !=
this )
return old;
164 CAT newcat =
new CAT(
this,t.length*2,0);
168 while( master.
_cat ==
this && !master.
CAS_cat(
this,newcat) ) {}
178 for(
long cnt : t )
sum += cnt;
186 if(
_t.length <= 64 )
return sum();
188 long millis = System.currentTimeMillis();
200 System.out.print(
"["+t[0]);
201 for(
int i=1; i<t.length; i++ )
202 System.out.print(
","+t[i]);
203 System.out.print(
"]");
volatile long _fuzzy_time
An auto-resizing table of.
static Unsafe getUnsafe()
Fetch the Unsafe.
int internal_size()
Return the internal counter striping factor.
Simple class to obtain access to the Unsafe object.
static boolean CAS(long[] A, int idx, long old, long nnn)
void add(long x)
Add the given value to current counter value.
CAT(CAT next, int sz, long init)
static final Unsafe _unsafe
void decrement()
add with -1
int intValue()
Same as get, included for completeness.
String toString()
Return the counter's.
static long rawIndex(long[] ary, int i)
boolean CAS_cat(CAT oldcat, CAT newcat)
volatile long _fuzzy_sum_cache
static final int MAX_SPIN
long estimate_get()
A cheaper get.
long longValue()
Same as get, included for completeness.
void increment()
add with +1
void print()
A more verbose print than toString, showing internal structure.
long add_if(long x, int hash, ConcurrentAutoTable master)
static AtomicReferenceFieldUpdater< ConcurrentAutoTable, CAT > _catUpdater