SystemClock:EndTime: eliminate even very small chance that infinite timer will expire
authorKarlson2k <k2k@narod.ru>
Sun, 18 Aug 2013 19:13:30 +0000 (23:13 +0400)
committerKarlson2k <k2k@narod.ru>
Tue, 15 Oct 2013 11:35:27 +0000 (15:35 +0400)
xbmc/threads/SystemClock.cpp
xbmc/threads/SystemClock.h

index 5bb749c..657a154 100644 (file)
@@ -28,6 +28,7 @@
 #else
 #include <time.h>
 #endif
+#include "SystemClock.h"
 
 namespace XbmcThreads
 {
@@ -52,4 +53,5 @@ namespace XbmcThreads
     }
     return (unsigned int)(now_time - start_time);
   }
+  const unsigned int EndTime::InfiniteValue = std::numeric_limits<unsigned int>::max();
 }
index faae72d..40038b3 100644 (file)
@@ -45,20 +45,23 @@ namespace XbmcThreads
     unsigned int startTime;
     unsigned int totalWaitTime;
   public:
+    static const unsigned int InfiniteValue;
     inline EndTime() : startTime(0), totalWaitTime(0) {}
     inline EndTime(unsigned int millisecondsIntoTheFuture) : startTime(SystemClockMillis()), totalWaitTime(millisecondsIntoTheFuture) {}
 
     inline void Set(unsigned int millisecondsIntoTheFuture) { startTime = SystemClockMillis(); totalWaitTime = millisecondsIntoTheFuture; }
 
-    inline bool IsTimePast() { return totalWaitTime == 0 ? true : (SystemClockMillis() - startTime) >= totalWaitTime; }
+    inline bool IsTimePast() { return totalWaitTime == InfiniteValue ? false : (totalWaitTime == 0 ? true : (SystemClockMillis() - startTime) >= totalWaitTime); }
 
     inline unsigned int MillisLeft()
     {
+      if (totalWaitTime == InfiniteValue)
+        return InfiniteValue;
       unsigned int timeWaitedAlready = (SystemClockMillis() - startTime);
       return (timeWaitedAlready >= totalWaitTime) ? 0 : (totalWaitTime - timeWaitedAlready);
     }
 
     inline void SetExpired() { totalWaitTime = 0; }
-    inline void SetInfinite() { totalWaitTime = std::numeric_limits<unsigned int>::max(); }
+    inline void SetInfinite() { totalWaitTime = InfiniteValue; }
   };
 }