Ejemplo n.º 1
0
        /// <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);
                }
            }
        }
Ejemplo n.º 2
0
		public void ShouldEnqueueAndDequeue ()
		{
			ConcurrentLinkedQueue<int> pool = new ConcurrentLinkedQueue<int>();
			
			pool.Enqueue (1);
			
			Assert.AreEqual (1, pool.Dequeue ());			
		}
Ejemplo n.º 3
0
        public void ShouldEnqueueAndDequeue()
        {
            ConcurrentLinkedQueue <int> pool = new ConcurrentLinkedQueue <int>();

            pool.Enqueue(1);

            Assert.AreEqual(1, pool.Dequeue());
        }
Ejemplo n.º 4
0
		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 ());
			}
		}
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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());
            }
        }
Ejemplo n.º 7
0
        /// <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);
        }