public virtual void AddClockEntry(ClockEntry entry) { lock (sync) { if (clockEntries.FindIndex(x => x.Handler == entry.Handler) != -1) { throw new ArgumentException("A clock entry with given handler already exists in the clock source."); } clockEntries.Add(entry); clockEntriesUpdateHandlers.Add(null); UpdateUpdateHandler(clockEntries.Count - 1); UpdateLimits(); } NotifyNumberOfEntriesChanged(clockEntries.Count - 1, clockEntries.Count); }
public virtual void AddClockEntry(ClockEntry entry) { lock(sync) { if(clockEntries.FindIndex(x => x.Handler == entry.Handler) != -1) { throw new ArgumentException("A clock entry with given handler already exists in the clock source."); } clockEntries.Add(entry); clockEntriesUpdateHandlers.Add(null); UpdateUpdateHandler(clockEntries.Count - 1); UpdateLimits(); } NotifyNumberOfEntriesChanged(clockEntries.Count - 1, clockEntries.Count); }
private static bool HandleDirectionDescendingPositiveRatio(ref ClockEntry entry, long ticks, ref long nearestTickIn) { var flag = false; entry.Value -= ticks * entry.Ratio; entry.ValueResiduum = 0; if (entry.Value <= 0) { flag = true; entry.Value = entry.Period; entry = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot)); } nearestTickIn = Math.Min(nearestTickIn, (entry.Value - 1) / entry.Ratio + 1); return(flag); }
private static bool HandleDirectionAscendingNegativeRatio(ref ClockEntry entry, long ticks, ref long nearestTickIn) { var flag = false; entry.Value += (ticks + entry.ValueResiduum) / -entry.Ratio; entry.ValueResiduum = (ticks + entry.ValueResiduum) % -entry.Ratio; if (entry.Value >= entry.Period) { flag = true; entry.Value = 0; entry = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot)); } nearestTickIn = Math.Min(nearestTickIn, (entry.Period - entry.Value) * -entry.Ratio); return(flag); }
private static bool HandleDirectionDescendingNegativeRatio(ref ClockEntry entry, long ticks, ref long nearestTickIn) { var flag = false; entry.Value -= (ticks + entry.ValueResiduum) / -entry.Ratio; entry.ValueResiduum = (ticks + entry.ValueResiduum) % -entry.Ratio; if (entry.Value <= 0) { // TODO: maybe issue warning if its lower than zero flag = true; entry.Value = entry.Period; entry = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot)); } nearestTickIn = Math.Min(nearestTickIn, entry.Value * -entry.Ratio); return(flag); }
private static bool HandleDirectionAscendingNegativeRatio(ref ClockEntry entry, long ticks, ref long nearestTickIn) { var flag = false; entry.Value += (ticks + entry.ValueResiduum) / -entry.Ratio; entry.ValueResiduum = (ticks + entry.ValueResiduum) % -entry.Ratio; if(entry.Value >= entry.Period) { flag = true; entry.Value = 0; entry = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot)); } nearestTickIn = Math.Min(nearestTickIn, (entry.Period - entry.Value) * -entry.Ratio); return flag; }
private static bool HandleDirectionDescendingNegativeRatio(ref ClockEntry entry, long ticks, ref long nearestTickIn) { var flag = false; entry.Value -= (ticks + entry.ValueResiduum) / -entry.Ratio; entry.ValueResiduum = (ticks + entry.ValueResiduum) % -entry.Ratio; if(entry.Value <= 0) { // TODO: maybe issue warning if its lower than zero flag = true; entry.Value = entry.Period; entry = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot)); } nearestTickIn = Math.Min(nearestTickIn, entry.Value * -entry.Ratio); return flag; }
private static bool HandleDirectionDescendingPositiveRatio(ref ClockEntry entry, long ticks, ref long nearestTickIn) { var flag = false; entry.Value -= ticks * entry.Ratio; entry.ValueResiduum = 0; if(entry.Value <= 0) { flag = true; entry.Value = entry.Period; entry = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot)); } nearestTickIn = Math.Min(nearestTickIn, (entry.Value - 1) / entry.Ratio + 1); return flag; }
void IClockSource.AddClockEntry(ClockEntry entry) { ClockSource.AddClockEntry(entry); }
private void InternalReset() { frequency = initialFrequency; var clockEntry = new ClockEntry(initialLimit, ClockEntry.FrequencyToRatio(this, frequency), OnLimitReached, initialEnabled, initialDirection, initialWorkMode) { Value = initialDirection == Direction.Ascending ? 0 : initialLimit }; clockSource.ExchangeClockEntryWith(OnLimitReached, x => clockEntry, () => clockEntry); divider = 1; EventEnabled = false; }
public void Reset() { var clockEntry = new ClockEntry((1 << 29) - 1, ClockEntry.FrequencyToRatio(this, 1000000), OnLimitReached, false) { Value = 0 }; clockSource.ExchangeClockEntryWith(OnLimitReached, x => clockEntry, () => clockEntry); }
public override void AddClockEntry(ClockEntry entry) { base.AddClockEntry(entry); QuicklyRestartUpdateThread(); CheckThread(); }