private void Enqueue(_ExecEvent ee) { //Console.WriteLine("Enqueueing #" + ee.m_key + ", its time is " + (new DateTime(ee.m_when)).ToString()); int ndx = 1; if (m_numEventsPending == m_eventArraySize) { GrowArray(); } m_numEventsPending++; if (!ee.IsDaemon) { m_numNonDaemonEventsPending++; } ndx = m_numEventsPending; int parentNdx = ndx / 2; m_parentEvent = m_eventArray[parentNdx]; while (parentNdx > 0 && ee.When < m_parentEvent.When) // HEAP PROPERTY - root is lowest. { m_eventArray[ndx] = m_parentEvent; ndx = parentNdx; parentNdx /= 2; m_parentEvent = m_eventArray[parentNdx]; } m_eventArray[ndx] = ee; }
public _ExecEvent Take(ExecEventReceiver eer, DateTime when, object userData, long key, bool isDaemon) { if (m_head == m_tail) { // Queue is empty! m_tail = m_numExecEvents; m_head = 0; m_numExecEvents *= 2; m_execEventCache = new _ExecEvent[m_numExecEvents]; for (int i = m_head; i < m_tail; i++) { m_execEventCache[i] = new _ExecEvent(); } } _ExecEvent retval = m_execEventCache[m_head++]; if (m_head == m_numExecEvents) { m_head = 0; } retval.Eer = eer; retval.Key = key; retval.UserData = userData; retval.When = when.Ticks; retval.IsDaemon = isDaemon; return(retval); }
private void StartWocv() { m_runNumber++; while (m_numNonDaemonEventsPending > 0 && !m_stopRequested) { m_currentEvent = Dequeue(); m_eventCount++; m_now = new DateTime(m_currentEvent.When); #region TEMPORAL DEBUGGING if (m_hasTarget && (m_now.ToString().Equals(_targetdatestr) || (!m_hasFired && m_now > m_targetdate))) { m_hasFired = true; m_hoverHere = m_now.ToString(); System.Diagnostics.Debugger.Break(); } #endregion TEMPORAL DEBUGGING if (m_eventAboutToFire != null) { m_eventAboutToFire(m_currentEvent.Key, m_currentEvent.Eer, 0.0, m_now, m_currentEvent.UserData, ExecEventType.Synchronous); } m_currentEvent.Eer(this, m_currentEvent.UserData); if (m_eventHasCompleted != null) { m_eventHasCompleted(m_currentEvent.Key, m_currentEvent.Eer, 0.0, m_now, m_currentEvent.UserData, ExecEventType.Synchronous); } m_execEventCache.Return(m_currentEvent); } }
public ExecEventCache(int initialEventCacheSize) { m_numExecEvents = initialEventCacheSize; m_execEventCache = new _ExecEvent[m_numExecEvents]; for (int i = 0; i < initialEventCacheSize; i++) { m_execEventCache[i] = new _ExecEvent(); } }
public void Return(_ExecEvent execEvent) { m_execEventCache[m_tail++] = execEvent; // Comment out for better performance. execEvent.Key = -1; execEvent.UserData = null; execEvent.Eer = null; execEvent.When = 0L; if (m_tail == m_numExecEvents) { m_tail = 0; } }
private _ExecEvent Dequeue() { if (m_numEventsPending == 0) { return(null); } _ExecEvent leastEvent = m_eventArray[1]; _ExecEvent relocatee = m_eventArray[m_numEventsPending]; m_numEventsPending--; int ndx = 1; int child = 2; while (child <= m_numEventsPending) { if (child < m_numEventsPending && m_eventArray[child].When > m_eventArray[child + 1].When) { child++; } // m_entryArray[child] is the (e.g. in a minTree) lesser of the two children. // Therefore, if m_entryArray[child] is greater than relocatee, put Relocatee // in at ndx, and we're done. Otherwise, swap and drill down some more. if (m_eventArray[child].When > relocatee.When) { break; } m_eventArray[ndx] = m_eventArray[child]; ndx = child; child *= 2; } m_eventArray[ndx] = relocatee; //Console.WriteLine("Dequeueing #" + leastEvent.m_key + ", its time is " + (new DateTime(leastEvent.m_when)).ToString()); if (!leastEvent.IsDaemon) { m_numNonDaemonEventsPending--; } return(leastEvent); }
private void StartWcv() { m_runNumber++; while (m_numNonDaemonEventsPending > 0 && !m_stopRequested) { m_currentEvent = Dequeue(); m_eventCount++; if (m_now.Ticks > m_currentEvent.When) { string who = m_currentEvent.Eer.Target.GetType().FullName; if (m_currentEvent.Eer.Target is IHasName) { who = ((IHasName)m_currentEvent.Eer.Target).Name; } string method = m_currentEvent.Eer.Method.Name + "(...)"; if (true) { m_currentEvent.When = m_now.Ticks;// System.Diagnostics.Debugger.Break(); } else { // throw new ApplicationException(msg); } } m_lastEventServiceTime = m_now; m_now = new DateTime(m_currentEvent.When); if (m_eventAboutToFire != null) { m_eventAboutToFire(m_currentEvent.Key, m_currentEvent.Eer, 0.0, m_now, m_currentEvent.UserData, ExecEventType.Synchronous); } m_currentEvent.Eer(this, m_currentEvent.UserData); if (m_eventHasCompleted != null) { m_eventHasCompleted(m_currentEvent.Key, m_currentEvent.Eer, 0.0, m_now, m_currentEvent.UserData, ExecEventType.Synchronous); } m_execEventCache.Return(m_currentEvent); } }