public void SetUp() { _service = new SchedulingServiceImpl(new TimeSourceServiceImpl()); _mgmtService = new SchedulingMgmtServiceImpl(); // 2-by-2 table of buckets and slots var buckets = new ScheduleBucket[3]; _slots = new ScheduleSlot[buckets.Length][]; for (int i = 0; i < buckets.Length; i++) { buckets[i] = _mgmtService.AllocateBucket(); _slots[i] = new ScheduleSlot[2]; for (int j = 0; j < _slots[i].Length; j++) { _slots[i][j] = buckets[i].AllocateSlot(); } } _callbacks = new SupportScheduleCallback[5]; for (int i = 0; i < _callbacks.Length; i++) { _callbacks[i] = new SupportScheduleCallback(); } }
private void AddTrigger(ScheduleSlot slot, ScheduleHandle handle, long triggerTime) { var handleSet = _timeHandleMap.Get(triggerTime); if (handleSet == null) { handleSet = new NullableDictionary <ScheduleSlot, ScheduleHandle>( new OrderedDictionary <ScheduleSlot, ScheduleHandle>()); _timeHandleMap.Put(triggerTime, handleSet); } handleSet.Put(slot, handle); _handleSetMap.Put(handle, handleSet); }
public void TestCompare() { ScheduleSlot[] slots = new ScheduleSlot[10]; slots[0] = new ScheduleSlot(1, 1); slots[1] = new ScheduleSlot(1, 2); slots[2] = new ScheduleSlot(2, 1); slots[3] = new ScheduleSlot(2, 2); Assert.AreEqual(-1, slots[0].CompareTo(slots[1])); Assert.AreEqual(1, slots[1].CompareTo(slots[0])); Assert.AreEqual(0, slots[0].CompareTo(slots[0])); Assert.AreEqual(-1, slots[0].CompareTo(slots[2])); Assert.AreEqual(-1, slots[1].CompareTo(slots[2])); Assert.AreEqual(1, slots[2].CompareTo(slots[0])); Assert.AreEqual(1, slots[2].CompareTo(slots[1])); }
public void Add(long afterMSec, ScheduleHandle handle, ScheduleSlot slot) { using (Instrument.With( i => i.QScheduleAdd(_currentTime, afterMSec, handle, slot), i => i.AScheduleAdd())) { using (_uLock.Acquire()) { if (_handleSetMap.ContainsKey(handle)) { Remove(handle, slot); } long triggerOnTime = _currentTime + afterMSec; AddTrigger(slot, handle, triggerOnTime); } } }
public void Remove(ScheduleHandle handle, ScheduleSlot slot) { using (Instrument.With( i => i.QScheduleRemove(handle, slot), i => i.AScheduleRemove())) { using (_uLock.Acquire()) { var handleSet = _handleSetMap.Get(handle); if (handleSet == null) { // If it already has been removed then that's fine; // Such could be the case when 2 timers fireStatementStopped at the same time, and one stops the other return; } handleSet.Remove(slot); _handleSetMap.Remove(handle); } } }