public bool TimedOut() { if (_endTick.GetInt64Value() == 0) { return(true); } Tick currentTick = _os.GetTickManager().GetTick(); return(currentTick >= _endTick); }
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(); } }
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)); }
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)); } }
public static Tick GetCurrentTickOrdered(this OsState os) => os.GetTickManager().GetSystemTickOrdered();
public static Tick GetCurrentTick(this OsState os) => os.GetTickManager().GetTick();
public static Tick ConvertToTick(this OsState os, TimeSpan ts) => os.GetTickManager().ConvertToTick(ts);
public static TimeSpan ConvertToTimeSpan(this OsState os, Tick tick) => os.GetTickManager().ConvertToTimespan(tick);
public static long GetSystemTickFrequency(this OsState os) => os.GetTickManager().GetTickFrequency();
public static Tick GetSystemTick(this OsState os) => os.GetTickManager().GetTick();