/// <summary> /// Notifies the send queue to process more data. /// </summary> private void NotifySendQueue() { if (Interlocked.CompareExchange(ref sendState, 1, 0) == 0) { SendQueueState nextState; if (sendQueue.Dequeue(out nextState)) { try { Promise <ChunkedBuffer> promise = nextState.buffer.DrainToStream(stream); promise.State = nextState; promise.OnFulfilled = QueueWriteCallback; } catch (Exception e) { SockNetLogger.Log(SockNetLogger.LogLevel.ERROR, this, "Send data to the socket stream failed.", e); } } else { Interlocked.CompareExchange(ref sendState, 0, 1); } } }
public void ShouldEnqueueAndDequeue () { ConcurrentLinkedQueue<int> pool = new ConcurrentLinkedQueue<int>(); pool.Enqueue (1); Assert.AreEqual (1, pool.Dequeue ()); }
public void ShouldEnqueueAndDequeue() { ConcurrentLinkedQueue <int> pool = new ConcurrentLinkedQueue <int>(); pool.Enqueue(1); Assert.AreEqual(1, pool.Dequeue()); }
public void ShouldEnqueueAndDequeueMultiple () { ConcurrentLinkedQueue<int> pool = new ConcurrentLinkedQueue<int>(); for (int i = 1; i <= 10; i++) { pool.Enqueue (i); } for (int i = 1; i <= 10; i++) { Assert.AreEqual (i, pool.Dequeue ()); } }
public MessagingContext GetContext(string host) { MessagingContext context = pool.Dequeue(); if (context == null) { context = new MessagingContext(messageFactory, host, createConnectionDelegate); context.Pool = this; } context.Host = host; return(context); }
public void ShouldEnqueueAndDequeueMultiple() { ConcurrentLinkedQueue <int> pool = new ConcurrentLinkedQueue <int>(); for (int i = 1; i <= 10; i++) { pool.Enqueue(i); } for (int i = 1; i <= 10; i++) { Assert.AreEqual(i, pool.Dequeue()); } }
/// <summary> /// Borrows an object from the pool. /// </summary> /// <returns></returns> public PooledObject <T> Borrow() { PooledObject <T> pooledObject = null; if (pool.Dequeue(out pooledObject)) { Interlocked.Decrement(ref availableObjects); if (onUpdateObject != null) { pooledObject.Value = onUpdateObject(pooledObject.Value); } } else { pooledObject = new PooledObject <T>(this, onNewObject()); Interlocked.Increment(ref totalPoolSize); } pooledObject._state = (int)PooledObjectState.USED; return(pooledObject); }