Esempio n. 1
0
 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;
 }
Esempio n. 2
0
        protected void Insert(T value)
        {
            --offerSideOfferPermits;
            LinkedNode <T> p = new LinkedNode <T>(value);

            lock (tail)
            {
                tail.Next = p;
                tail      = p;
            }
        }
Esempio n. 3
0
 public T Peek()
 {
     lock (head)
     {
         LinkedNode <T> first = head.Next;
         if (first != null)
         {
             return(first.Value);
         }
         else
         {
             return(null);
         }
     }
 }
Esempio n. 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);
         }
     }
 }
Esempio n. 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);
         }
     }
 }
Esempio n. 6
0
 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);
         }
     }
 }
Esempio n. 7
0
 public LinkedQueue()
 {
     head = new LinkedNode <T>(default(T));
     last = head;
 }