private void put(LocalInstance<AGGREGATOR, SAMPLE> q) { // Has to set registered before adding to the list. Otherwise, the // instance might be removed from the list, set as unregistered, and // then the local thread might happily remove that information. The Java // memory model is a guarantuee for the minimum amount of visibility, // not a definition of the actual amount. q.setRegistered(true); synchronized (directoryLock) { directory.add(q); } }
AGGREGATOR getAndReset(Updater<AGGREGATOR, SAMPLE> updater) { AGGREGATOR previous; synchronized (lock) { previous = current; current = updater.createGenerationInstance(previous); setRegistered(false); } return previous; }