private final static boolean CAS( long[] A, int idx, long old, long nnn ) { assert idx >= 0 && idx < A.length; if ( _unsafe != null ) { final int rawIndex = _Lbase + idx * _Lscale; return _unsafe.compareAndSwapLong( A, rawIndex, old, nnn ); } return CASnoUnsafe(A, idx, old, nnn); }
String toString( long mask ) { return Long.toString(sum(mask)); }
private long add_if_mask( long x, long mask ) { return _cat.add_if_mask(x,mask,hash(),this); }
/** Same as {@link #get}, included for completeness. */ public long longValue() { return _cat.sum(0); }
String toString( long mask ) { return Long.toString(sum(mask)); }
private long add_if_mask( long x, long mask ) { return _cat.add_if_mask(x,mask,hash(),this); }
/** Same as {@link #get}, included for completeness. */ public int intValue() { return (int)_cat.sum(0); } /** Same as {@link #get}, included for completeness. */
/** Same as {@link #get}, included for completeness. */ public long longValue() { return _cat.sum(0); }
/** * Return the counter's {@code long} value converted to a string. */ public String toString() { return _cat.toString(0); }
/** * Return the counter's {@code long} value converted to a string. */ public String toString() { return _cat.toString(0); }
/** Same as {@link #get}, included for completeness. */ public int intValue() { return (int)_cat.sum(0); } /** Same as {@link #get}, included for completeness. */
public void all_and( long mask ) { long[] t = _t; for( int i=0; i<t.length; i++ ) { boolean done = false; while( !done ) { long old = t[i]; done = CAS(t,i, old, old&mask ); } } if( _next != null ) _next.all_and(mask); if( _sum_cache != Long.MIN_VALUE ) _sum_cache = Long.MIN_VALUE; // Blow out cache }
public void all_and( long mask ) { long[] t = _t; for( int i=0; i<t.length; i++ ) { boolean done = false; while( !done ) { long old = t[i]; done = CAS(t,i, old, old&mask ); } } if( _next != null ) _next.all_and(mask); if( _sum_cache != Long.MIN_VALUE ) _sum_cache = Long.MIN_VALUE; // Blow out cache }
public void all_set( long val ) { long[] t = _t; for( int i=0; i<t.length; i++ ) t[i] = val; if( _next != null ) _next.all_set(val); if( _sum_cache != Long.MIN_VALUE ) _sum_cache = Long.MIN_VALUE; // Blow out cache }
public long estimate_sum( long mask ) { // For short tables, just do the work if( _t.length <= 64 ) return sum(mask); // For bigger tables, periodically freshen a cached value long millis = System.currentTimeMillis(); if( _fuzzy_time != millis ) { // Time marches on? _fuzzy_sum_cache = sum(mask); // Get sum the hard way _fuzzy_time = millis; // Indicate freshness of cached value } return _fuzzy_sum_cache; // Return cached sum }
public long sum( long mask ) { long sum = _sum_cache; if( sum != Long.MIN_VALUE ) return sum; sum = _next == null ? 0 : _next.sum(mask); // Recursively get cached sum long[] t = _t; for( int i=0; i<t.length; i++ ) sum += t[i]&(~mask); _sum_cache = sum; // Cache includes recursive counts return sum; }
/** * Current value of the counter. Since other threads are updating furiously * the value is only approximate, but it includes all counts made by the * current thread. Requires a pass over the internally striped counters. */ public long get() { return _cat.sum(0); } /** Same as {@link #get}, included for completeness. */
public void all_or ( long mask ) { long[] t = _t; for( int i=0; i<t.length; i++ ) { boolean done = false; while( !done ) { long old = t[i]; done = CAS(t,i, old, old|mask ); } } if( _next != null ) _next.all_or(mask); if( _sum_cache != Long.MIN_VALUE ) _sum_cache = Long.MIN_VALUE; // Blow out cache }