public BoundedLinkedQueue(int initialCapacity)
 {
     if (initialCapacity <= 0)
     {
         throw new ArgumentException("Capactity must be greater than zero", "initialCapacity");
     }
     capacity = initialCapacity;
     offerSideOfferPermits = initialCapacity;
     head = new LinkedNode <T>(default(T));
     tail = head;
 }
        protected void Insert(T value)
        {
            --offerSideOfferPermits;
            LinkedNode <T> p = new LinkedNode <T>(value);

            lock (tail)
            {
                tail.Next = p;
                tail      = p;
            }
        }
Example #3
0
 public T Peek()
 {
     lock (head)
     {
         LinkedNode <T> first = head.Next;
         if (first != null)
         {
             return(first.Value);
         }
         else
         {
             return(null);
         }
     }
 }
Example #4
0
 protected void Insert(T value)
 {
     lock (offerLock)
     {
         LinkedNode <T> p = new LinkedNode <T>(value);
         lock (last)
         {
             last.Next = p;
             last      = p;
             Interlocked.Increment(ref offerCount);
         }
         if (waitingForPoll > 0)
         {
             Monitor.Pulse(offerLock);
         }
     }
 }
Example #5
0
 protected T Extract()
 {
     lock (this)
     {
         lock (head)
         {
             T x = null;
             LinkedNode <T> first = head.Next;
             if (first != null)
             {
                 x           = first.Value;
                 first.Value = null;
                 head        = first;
                 Interlocked.Increment(ref pollCount);
             }
             return(x);
         }
     }
 }
 protected T Extract()
 {
     lock (this)
     {
         lock (head)
         {
             T x = default(T);
             LinkedNode <T> first = head.Next;
             if (first != null)
             {
                 x           = first.Value;
                 first.Value = default(T);
                 head        = first;
                 ++pollSideOfferPermits;
                 Monitor.Pulse(this);
             }
             return(x);
         }
     }
 }
Example #7
0
 public LinkedQueue()
 {
     head = new LinkedNode <T>(default(T));
     last = head;
 }