/// <summary> /// Releases all resources allocated by this instance /// </summary> public void Dispose() { // this is not a graceful shutdown // if someone uses a pooled item then 99% that an exception will be thrown // somewhere. But since the dispose is mostly used when everyone else is finished // this should not kill any kittens lock (this) { CheckDisposed(); isDisposed = true; using (itemReleasedEvent) itemReleasedEvent.Reset(); itemReleasedEvent = null; PooledSocket ps; while (freeItems.Dequeue(out ps)) { try { ps.Destroy(); } catch (Exception ex) { Debug.WriteLine(ex.Message); throw; } } freeItems = null; } }
internal InternalPoolImpl(IPEndPoint endpoint, ISocketPoolConfiguration config) { isAlive = true; endPoint = endpoint; this.config = config; minItems = config.MinPoolSize; maxItems = config.MaxPoolSize; if (minItems < 0) { throw new InvalidOperationException("minItems must be larger than 0", null); } if (maxItems < minItems) { throw new InvalidOperationException("maxItems must be larger than minItems", null); } if (this.config.ConnectionTimeout < TimeSpan.Zero) { throw new InvalidOperationException("connectionTimeout must be >= TimeSpan.Zero", null); } freeItems = new InterlockedQueue <PooledSocket>(); itemReleasedEvent = new AutoResetEvent(false); InitPool(); }
/// <summary> /// Releases all resources allocated by this instance /// </summary> public void Dispose() { if (!this.isDisposed) { // this is not a graceful shutdown // if someone uses a pooled item then 99% that an exception will be thrown // somewhere. But since the dispose is mostly used when everyone else is finished // this should not kill any kittens lock (this) { if (!this.isDisposed) { this.isAlive = false; this.isDisposed = true; PooledSocket ps; while (this.freeItems.Dequeue(out ps)) { try { ps.Destroy(); } catch { } } this.ownerNode = null; this.semaphore.Close(); this.semaphore = null; this.freeItems = null; } } } }
internal InternalPoolImpl(MemcachedNode ownerNode, ISocketPoolConfiguration config) { this.ownerNode = ownerNode; this.isAlive = true; this.endPoint = ownerNode.EndPoint; this.config = config; this.minItems = config.MinPoolSize; this.maxItems = config.MaxPoolSize; if (this.minItems < 0) { throw new InvalidOperationException("minItems must be larger than 0", null); } if (this.maxItems < this.minItems) { throw new InvalidOperationException("maxItems must be larger than minItems", null); } if (this.config.ConnectionTimeout < TimeSpan.Zero) { throw new InvalidOperationException("connectionTimeout must be >= TimeSpan.Zero", null); } this.semaphore = new Semaphore(minItems, maxItems); this.freeItems = new InterlockedQueue <PooledSocket>(); }
public SlidingBuffer(int chunkSize) { this.chunkSize = chunkSize; this.buffers = new InterlockedQueue<Segment>(); }
public SlidingBuffer(int chunkSize) { this.chunkSize = chunkSize; this.buffers = new InterlockedQueue <Segment>(); }