- final @Nullable Collection<T> ensureClosed() {
- @SuppressWarnings("unchecked")
- final State<T> local = STATE_UPDATER.getAndSet(this, null);
- return local == null ? null : local.values();
+ final @Nullable Map<Long, T> ensureClosed() {
+ // volatile read and a conditional CAS. This ends up being better in the typical case when we are invoked more
+ // than once (see ClientBackedTransaction) than performing a STATE_UPDATER.getAndSet().
+ final State<T> local = state;
+ return local != null && STATE_UPDATER.compareAndSet(this, local, null) ? local : null;