Bläddra i källkod

BTime: add btime_gettime(). BReactor: use btime_gettime().

ambrop7 15 år sedan
förälder
incheckning
66c5c08eeb
2 ändrade filer med 20 tillägg och 16 borttagningar
  1. 1 16
      system/BReactor.c
  2. 19 0
      system/BTime.h

+ 1 - 16
system/BReactor.c

@@ -720,22 +720,7 @@ void BReactor_SetTimer (BReactor *bsys, BTimer *bt)
 
 void BReactor_SetTimerAfter (BReactor *bsys, BTimer *bt, btime_t after)
 {
-    btime_t now = btime_gettime();
-    
-    // handle overflow
-    int overflows = add_int64_overflows(now, after);
-    btime_t absTime;
-    if (overflows != 0) {
-        if (overflows > 0) {
-            absTime = INT64_MAX;
-        } else {
-            absTime = INT64_MIN;
-        }
-    } else {
-        absTime = now + after;
-    }
-    
-    BReactor_SetTimerAbsolute(bsys, bt, absTime);
+    BReactor_SetTimerAbsolute(bsys, bt, btime_add(btime_gettime(), after));
 }
 
 void BReactor_SetTimerAbsolute (BReactor *bsys, BTimer *bt, btime_t time)

+ 19 - 0
system/BTime.h

@@ -36,6 +36,7 @@
 #include <stdint.h>
 
 #include <misc/debug.h>
+#include <misc/overflow.h>
 
 typedef int64_t btime_t;
 
@@ -90,4 +91,22 @@ static btime_t btime_gettime ()
     #endif
 }
 
+static btime_t btime_add (btime_t t1, btime_t t2)
+{
+    // handle overflow
+    int overflows = add_int64_overflows(t1, t2);
+    btime_t sum;
+    if (overflows != 0) {
+        if (overflows > 0) {
+            sum = INT64_MAX;
+        } else {
+            sum = INT64_MIN;
+        }
+    } else {
+        sum = t1 + t2;
+    }
+    
+    return sum;
+}
+
 #endif