Esempio n. 1
0
 /// <summary> Inserts the specified element into the priority queue.The inserting of element is done in
 /// synchronization When the element is inserted successfully then it notifies the waiting thread
 /// </summary>
 /// <param name="o">the element to add </param>
 /// <returns> true </returns>
 public bool offer(Object o)
 {
     if (o == null)
     {
         throw new NullReferenceException();
     }
     Monitor.Enter(this);
     try
     {
         bool ok = _queue.offer(o);
         if (_timeFirstEvent == 0)
         // adding first event in sequence
         {
             // background event doesn't count
             if (!isBackgroundEvent(o))
             {
                 _timeFirstEvent = Misc.getSystemMilliseconds();
             }
         }
         Debug.Assert(ok);
         Monitor.Pulse(this);
         return(true);
     }
     finally
     {
         Monitor.Exit(this);
     }
 }
Esempio n. 2
0
        /// <summary> This method (implemented from MgBlockingQueue) offers the blocking mechanism. Any thread entering in
        /// this method will wait if the queue is empty and it will be notified when an element is inserted in the
        /// queue
        /// </summary>
        public void waitForElement()
        {
            Monitor.Enter(this);
            try
            {
                // we finished handling of previous events, and there is no other events in queue
                // the sequence is finished
                if (_queue.Size == 0)
                {
                    _timeFirstEvent = 0;
                }

                while (_queue.Size == 0)
                {
                    Monitor.Wait(this);
                }
            }
            catch (ThreadInterruptedException)
            {
                Monitor.Pulse(this); // propagate to non-interrupted thread
                throw new ApplicationException("In waitForElement");
            }
            finally
            {
                Monitor.Exit(this);
            }
        }
Esempio n. 3
0
 /// <summary> Atomically removes all of the elements from this queue. The queue will be empty after this call returns.</summary>
 internal void clear()
 {
     Monitor.Enter(this);
     try
     {
         _queue.clear();
     }
     finally
     {
         Monitor.Exit(this);
     }
 }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 internal bool isEmpty()
 {
     Monitor.Enter(this);
     try
     {
         return(_queue.isEmpty());
     }
     finally
     {
         Monitor.Exit(this);
     }
 }
Esempio n. 5
0
 /// <summary> Always returns <tt>Integer.MAX_VALUE</tt> because a <tt>PriorityBlockingQueue</tt> is not capacity
 /// constrained.
 /// </summary>
 /// <returns> <tt>Integer.MAX_VALUE</tt>
 /// </returns>
 internal int remainingCapacity()
 {
     Monitor.Enter(this);
     try
     {
         return(Int32.MaxValue);
     }
     finally
     {
         Monitor.Exit(this);
     }
 }
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 internal int size()
 {
     Monitor.Enter(this);
     try
     {
         return(_queue.Size);
     }
     finally
     {
         Monitor.Exit(this);
     }
 }
Esempio n. 7
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 internal Object peek()
 {
     Monitor.Enter(this);
     try
     {
         return(_queue.peek());
     }
     finally
     {
         Monitor.Exit(this);
     }
 }
Esempio n. 8
0
 /// <summary>
 ///  Return time of first event in sequence
 /// </summary>
 /// <returns> </returns>
 internal long GetTime()
 {
     Monitor.Enter(this);
     try
     {
         return(_timeFirstEvent);
     }
     finally
     {
         Monitor.Exit(this);
     }
 }
Esempio n. 9
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        internal Object poll()
        {
            Monitor.Enter(this);
            try
            {
                Object e = _queue.poll();
                // background event priority is lowest , executing this event means that there are no
                // real events in the queue
                if (isBackgroundEvent(e))
                {
                    _timeFirstEvent = 0;
                }

                return(e);
            }
            finally
            {
                Monitor.Exit(this);
            }
        }