/// <summary> /// Allocate a new swapper id for the given <seealso cref="PageSwapper"/>. /// </summary> internal int Allocate(PageSwapper swapper) { lock (this) { SwapperMapping[] swapperMappings = this._swapperMappings; // First look for an available freed slot. lock ( _free ) { if (!_free.Empty) { int id = _free.intIterator().next(); _free.remove(id); swapperMappings[id] = new SwapperMapping(id, swapper); this._swapperMappings = swapperMappings; // Volatile store synchronizes-with loads in getters. return(id); } } // No free slot was found above, so we extend the array to make room for a new slot. int id = swapperMappings.Length; if (id + 1 > _maxSwapperId) { throw new System.InvalidOperationException("All swapper ids are allocated: " + _maxSwapperId); } swapperMappings = Arrays.copyOf(swapperMappings, id + 1); swapperMappings[id] = new SwapperMapping(id, swapper); this._swapperMappings = swapperMappings; // Volatile store synchronizes-with loads in getters. return(id); } }
private bool NextFromTxState() { if (_txTypeIterator == null && !_txTypes.Empty) { _txTypeIterator = _txTypes.intIterator(); //here it may be tempting to do txTypes.clear() //however that will also clear the iterator } if (_txTypeIterator != null && _txTypeIterator.hasNext()) { _storeCursor.setCurrent(_txTypeIterator.next(), NO_ID, NO_ID, NO_ID); return(true); } return(false); }