/** * Add the given value to current counter value. Concurrent updates will * not be lost, but addAndGet or getAndAdd are not implemented because the * total counter value (i.e., {@link #get}) is not atomically updated. * Updates are striped across an array of counters to avoid cache contention * and has been tested with performance scaling linearly up to 768 CPUs. */ public void add( long x ) { add_if_mask( x,0); } /** {@link #add} with -1 */
/** * Add the value to the counter. * * @see ConcurrentAutoTable#add(long) */ final public void add(long x) { cat.add(x); }
public long get() { return cat.get(); //return al.get(); } }
/** * Atomically set the sum of the striped counters to specified value. Rather more expensive than a simple store, in * order to remain atomic. */ public void set(long x) { CAT newcat = new CAT(null, 4, x); // Spin until CAS works while (!CAS_cat(_cat, newcat)) { /**/ } }
private long add_if_mask(long x, long mask) { return _cat.add_if_mask(x, mask, hash(), this); }
/** * Set the value of the counter. * * @see ConcurrentAutoTable#set(long) */ final public void set(long x) { cat.set(x); }
/** * Increment the value of the counter. * * @see ConcurrentAutoTable#increment() */ final public void increment() { cat.increment(); }
/** * Initialize a new counter with a value of <code>0L</code>. */ public CAT() { cat = new ConcurrentAutoTable(); }
/** Decrement the value of the counter. * * @see ConcurrentAutoTable#decrement() */ final public void decrement() { cat.decrement(); }
/** Atomically set the sum of the striped counters to specified value. * Rather more expensive than a simple store, in order to remain atomic. */ public void set( long x ) { CAT newcat = new CAT(null,4,x); // Spin until CAS works while( !CAS_cat(_cat,newcat) ); }
private long add_if_mask( long x, long mask ) { return _cat.add_if_mask(x,mask,hash(),this); }
/** * Set the value of the counter. * * @see ConcurrentAutoTable#set(long) */ final public void set(long x) { cat.set(x); }
/** * Increment the value of the counter. * * @see ConcurrentAutoTable#increment() */ final public void increment() { cat.increment(); }
/** * Initialize a new counter with a value of <code>0L</code>. */ public CAT() { cat = new ConcurrentAutoTable(); }
/** Decrement the value of the counter. * * @see ConcurrentAutoTable#decrement() */ final public void decrement() { cat.decrement(); }
/** * Add the given value to current counter value. Concurrent updates will * not be lost, but addAndGet or getAndAdd are not implemented because the * total counter value (i.e., {@link #get}) is not atomically updated. * Updates are striped across an array of counters to avoid cache contention * and has been tested with performance scaling linearly up to 768 CPUs. */ public void add( long x ) { add_if_mask( x,0); } /** {@link #add} with -1 */
/** Atomically set the sum of the striped counters to specified value. * Rather more expensive than a simple store, in order to remain atomic. */ public void set( long x ) { CAT newcat = new CAT(null,4,x); // Spin until CAS works while( !CAS_cat(_cat,newcat) ); }
private long add_if_mask( long x, long mask ) { return _cat.add_if_mask(x,mask,hash(),this); }
/** * Current value of the counter. * * @see ConcurrentAutoTable#get() */ final public long get() { return cat.get(); }
public void reset() { cat.set(0); //al.set(0); }