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 HandleDirectionAscendingPositiveRatio(ref ClockEntry entry, TimeInterval time, ref TimeInterval nearestTickIn) { var flag = false; entry.Value += time.Ticks * (ulong)entry.Ratio; entry.ValueResiduum = 0; if (entry.Value >= entry.Period) { flag = true; entry.Value = 0; entry = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot)); } nearestTickIn = nearestTickIn.WithTicksMin((entry.Period - entry.Value - 1) / (ulong)entry.Ratio + 1); return(flag); }
private static bool HandleDirectionAscendingNegativeRatio(ref ClockEntry entry, TimeInterval time, ref TimeInterval nearestTickIn) { var flag = false; ulong ratio = (ulong)(-entry.Ratio); entry.Value += (time.Ticks + entry.ValueResiduum) / ratio; entry.ValueResiduum = (time.Ticks + entry.ValueResiduum) % ratio; if (entry.Value >= entry.Period) { flag = true; entry.Value = 0; entry = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot)); } nearestTickIn = nearestTickIn.WithTicksMin(((entry.Period - entry.Value) * ratio) - entry.ValueResiduum); return(flag); }
public ClockEntry With(ulong?period = null, long?frequency = null, Action handler = null, bool?enabled = null, ulong?value = null, Direction?direction = null, WorkMode?workMode = null, long?step = null) { var result = new ClockEntry( period ?? Period, frequency ?? Frequency, handler ?? Handler, Owner, LocalName, enabled ?? Enabled, direction ?? Direction, workMode ?? WorkMode, step ?? Step); result.Value = value ?? Value; result.ValueResiduum = ValueResiduum; return(result); }
private static bool HandleDirectionDescendingPositiveRatio(ref ClockEntry entry, TimeInterval time, ref TimeInterval nearestTickIn) { var ticksByRatio = time.Ticks * (ulong)entry.Ratio; var isReached = ticksByRatio >= entry.Value; entry.ValueResiduum = 0; if (isReached) { entry.Value = entry.Period; entry = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot)); } else { entry.Value -= ticksByRatio; } nearestTickIn = nearestTickIn.WithTicksMin((entry.Value - 1) / (ulong)entry.Ratio + 1); return(isReached); }
private static bool HandleDirectionDescendingNegativeRatio(ref ClockEntry entry, TimeInterval time, ref TimeInterval nearestTickIn) { var ratio = (ulong)(-entry.Ratio); var ticksByRatio = (time.Ticks + entry.ValueResiduum) / ratio; var isReached = ticksByRatio >= entry.Value; entry.ValueResiduum = (time.Ticks + entry.ValueResiduum) % ratio; if (isReached) { // TODO: maybe issue warning if its lower than zero entry.Value = entry.Period; entry = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot)); } else { entry.Value -= ticksByRatio; } nearestTickIn = nearestTickIn.WithTicksMin(entry.Value * ratio + entry.ValueResiduum); return(isReached); }
public override void AddClockEntry(ClockEntry entry) { base.AddClockEntry(entry); QuicklyRestartUpdateThread(); CheckThread(); }