Ejemplo n.º 1
0
        public bool TimedOut()
        {
            if (_endTick.GetInt64Value() == 0)
            {
                return(true);
            }

            Tick currentTick = _os.GetTickManager().GetTick();

            return(currentTick >= _endTick);
        }
Ejemplo n.º 2
0
        public static void Sleep(OsState os, TimeSpan time)
        {
            if (time == new TimeSpan(0))
            {
                return;
            }

            TickManager tickManager = os.GetTickManager();

            // Attempt to avoid overflow by doing the addition unsigned
            ulong currentTick     = (ulong)tickManager.GetTick().GetInt64Value();
            ulong timeoutTick     = (ulong)tickManager.ConvertToTick(time).GetInt64Value();
            ulong absoluteEndTick = currentTick + timeoutTick + 1;

            var endTick = new Tick((long)Math.Min(long.MaxValue, absoluteEndTick));

            Tick curTick = tickManager.GetTick();

            // Sleep in a loop until the requested time has past.
            while (curTick < endTick)
            {
                Tick remaining   = endTick - curTick;
                int  sleepTimeMs = (int)ConvertToImplTime(os, remaining).GetMilliSeconds();

                System.Threading.Thread.Sleep(sleepTimeMs);

                curTick = tickManager.GetTick();
            }
        }
Ejemplo n.º 3
0
        public static TimeSpan ConvertToImplTime(OsState os, Tick tick)
        {
            TickManager tickManager = os.GetTickManager();
            TimeSpan    ts          = tickManager.ConvertToTimespan(tick);

            // .NET allows sleeping up to int.MaxValue milliseconds at a time.
            long timeMs = Math.Min(int.MaxValue, ts.GetMilliSeconds());

            return(TimeSpan.FromMilliSeconds(timeMs));
        }
Ejemplo n.º 4
0
        public TimeoutHelper(OsState os, TimeSpan timeout)
        {
            _os = os;

            if (timeout == new TimeSpan(0))
            {
                // If timeout is zero, don't do relative tick calculations.
                _endTick = new Tick(0);
            }
            else
            {
                TickManager tickManager = os.GetTickManager();

                // Attempt to avoid overflow by doing the addition unsigned
                ulong currentTick     = (ulong)tickManager.GetTick().GetInt64Value();
                ulong timeoutTick     = (ulong)tickManager.ConvertToTick(timeout).GetInt64Value();
                ulong absoluteEndTick = currentTick + timeoutTick + 1;

                _endTick = new Tick((long)Math.Min(long.MaxValue, absoluteEndTick));
            }
        }
Ejemplo n.º 5
0
 public static Tick GetCurrentTickOrdered(this OsState os) => os.GetTickManager().GetSystemTickOrdered();
Ejemplo n.º 6
0
 public static Tick GetCurrentTick(this OsState os) => os.GetTickManager().GetTick();
Ejemplo n.º 7
0
 public static Tick ConvertToTick(this OsState os, TimeSpan ts) => os.GetTickManager().ConvertToTick(ts);
Ejemplo n.º 8
0
 public static TimeSpan ConvertToTimeSpan(this OsState os, Tick tick) => os.GetTickManager().ConvertToTimespan(tick);
Ejemplo n.º 9
0
 public static long GetSystemTickFrequency(this OsState os) => os.GetTickManager().GetTickFrequency();
Ejemplo n.º 10
0
 public static Tick GetSystemTick(this OsState os) => os.GetTickManager().GetTick();