예제 #1
0
        /// <summary>
        /// Attempt to put an item (either a real CLR objecr or a "virtual"
        /// item) into the <see cref="BoundedBuffer"/>.
        /// </summary>
        /// <param name="producer">
        /// The <see cref="BufferPut"/> DesTask.
        /// </param>
        /// <param name="item">
        /// The object to put into the <see cref="BoundedBuffer"/>.
        /// </param>
        /// <param name="useItem">
        /// <b>true</b> if the <paramref name="item"/> parameter should be used.
        /// </param>
        /// <returns>
        /// <b>true</b> if <paramref name="producer"/> was blocked.
        /// </returns>
        private bool PutObject(BufferPut producer, object item, bool useItem)
        {
            bool blocked = Count >= Capacity;

            if (blocked)
            {
                if (_producerQ == null)
                {
                    _producerQ = CreateBlockingQueue(ProducerQueueId);
                }
                _producerQ.Enqueue(producer);
            }
            else
            {
                if (useItem)
                {
                    if (_items == null)
                    {
                        _items = new React.Queue.FifoQueue <object>();
                    }
                    _items.Enqueue(item);
                }
                else
                {
                    _count++;
                }

                producer.Activate(this);
                ResumeWaitingConsumers();
            }

            return(blocked);
        }
예제 #2
0
 /// <summary>
 /// Attempt to resume as many waiting producer <see cref="DesTask"/>s as
 /// possible.
 /// </summary>
 protected void ResumeWaitingProducers()
 {
     while (Count < Capacity && GetBlockCount(ProducerQueueId) > 0)
     {
         BufferPut task = (BufferPut)_producerQ.Dequeue();
         if (!task.Canceled && task.Client != null)
         {
             if (task.Item == null)
             {
                 PutObject(task);
             }
             else
             {
                 PutObject(task, task.Item);
             }
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Called by the <see cref="BufferPut"/> DesTask and the
 /// <see cref="ResumeWaitingProducers"/> method to put an
 /// object into the buffer.
 /// </summary>
 /// <param name="producer">
 /// The <see cref="BufferPut"/> DesTask.
 /// </param>
 /// <param name="item">
 /// The object to put into the <see cref="BoundedBuffer"/>.
 /// </param>
 /// <returns>
 /// <b>true</b> if <paramref name="producer"/> was blocked.
 /// </returns>
 internal bool PutObject(BufferPut producer, object item)
 {
     return(PutObject(producer, item, true));
 }
예제 #4
0
 /// <summary>
 /// Called by the <see cref="BufferPut"/> DesTask and the
 /// <see cref="ResumeWaitingProducers"/> method to put a
 /// counted item into the buffer.
 /// </summary>
 /// <param name="producer">
 /// The <see cref="BufferPut"/> DesTask.
 /// </param>
 /// <returns>
 /// <b>true</b> if <paramref name="producer"/> was blocked.
 /// </returns>
 internal bool PutObject(BufferPut producer)
 {
     return(PutObject(producer, null, false));
 }