/// <summary> /// Добавить новый элемент /// </summary> /// <param name="rawElement">Элемент</param> /// <param name="operations">Операции для элемента</param> /// <param name="makeAvailable">Сделать элемент сразу доступным для использования</param> /// <returns>Обёртка для нового элемента</returns> public PoolElementWrapper <T> Add(T rawElement, IPoolElementOperationSource <T> operations, bool makeAvailable) { Contract.Requires(operations != null); Debug.Assert(!_isDisposed); PoolElementWrapper <T> container = new PoolElementWrapper <T>(rawElement, operations, this); container.MakeBusy(); container.ThisIndex = _allElements.Add(container); Debug.Assert(container.ThisIndex >= 0 && container.ThisIndex < _allElements.Capacity); Debug.Assert(object.ReferenceEquals(container, _allElements.RawData[container.ThisIndex])); if (container.ThisIndex >= (1 << 16) - 2) { container.MarkElementDestroyed(); _allElements.RemoveAt(container.ThisIndex); container.MarkRemoved(); throw new InvalidOperationException("Can't add more elements. Max supported element count = " + ((1 << 16) - 2).ToString()); } if (makeAvailable) { ReleaseCore(container); } return(container); }
/// <summary> /// Добавить новый элемент /// </summary> /// <param name="rawElement">Элемент</param> /// <param name="operations">Операции для элемента</param> /// <param name="makeAvailable">Сделать элемент сразу доступным для использования</param> /// <returns>Обёртка для нового элемента</returns> public PoolElementWrapper <T> Add(T rawElement, IPoolElementOperationSource <T> operations, bool makeAvailable) { TurboContract.Requires(operations != null, conditionString: "operations != null"); TurboContract.Assert(!_isDisposed, conditionString: "!_isDisposed"); PoolElementWrapper <T> container = new PoolElementWrapper <T>(rawElement, operations, this); container.MakeBusyAtomic(); _allElements.Add(container); if (makeAvailable) { ReleaseCore(container); } return(container); }