/// <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); } }
/// <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); } }