Пример #1
0
        /// <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);
            }
        }
 /// <summary>
 /// Marks the given type as already seen </summary>
 /// <param name="type"> the type we have seen </param>
 private void MarkTypeAsSeen(int type)
 {
     _txTypes.remove(type);
 }