Beispiel #1
0
 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);
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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;
        }
Beispiel #7
0
        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;
        }
Beispiel #8
0
        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;
        }
Beispiel #9
0
 void IClockSource.AddClockEntry(ClockEntry entry)
 {
     ClockSource.AddClockEntry(entry);
 }
Beispiel #10
0
        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;
        }
Beispiel #11
0
 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();
 }
 public override void AddClockEntry(ClockEntry entry)
 {
     base.AddClockEntry(entry);
     QuicklyRestartUpdateThread();
     CheckThread();
 }