Просмотр исходного кода

BReactor: add BReactor_SetTimerAfter

ambrop7 15 лет назад
Родитель
Сommit
b21d45c00b
2 измененных файлов с 19 добавлено и 3 удалено
  1. 7 2
      system/BReactor.c
  2. 12 1
      system/BReactor.h

+ 7 - 2
system/BReactor.c

@@ -526,11 +526,16 @@ void BReactor_Quit (BReactor *bsys, int code)
 }
 
 void BReactor_SetTimer (BReactor *bsys, BTimer *bt)
+{
+    BReactor_SetTimerAfter(bsys, bt, bt->msTime);
+}
+
+void BReactor_SetTimerAfter (BReactor *bsys, BTimer *bt, btime_t after)
 {
     btime_t now = btime_gettime();
     
     // handle overflow
-    int overflows = add_int64_overflows(now, bt->msTime);
+    int overflows = add_int64_overflows(now, after);
     btime_t absTime;
     if (overflows != 0) {
         if (overflows > 0) {
@@ -539,7 +544,7 @@ void BReactor_SetTimer (BReactor *bsys, BTimer *bt)
             absTime = INT64_MIN;
         }
     } else {
-        absTime = now + bt->msTime;
+        absTime = now + after;
     }
     
     BReactor_SetTimerAbsolute(bsys, bt, absTime);

+ 12 - 1
system/BReactor.h

@@ -264,13 +264,24 @@ void BReactor_Quit (BReactor *bsys, int code);
  * The timer must have been initialized with {@link BTimer_Init}.
  * If the timer is in running state, it must be associated with this reactor.
  * The timer enters running state, associated with this reactor.
- * The timer's expiration time is set to the time argument.
  *
  * @param bsys the object
  * @param bt timer to start
  */
 void BReactor_SetTimer (BReactor *bsys, BTimer *bt);
 
+/**
+ * Starts a timer to expire after a given time.
+ * The timer must have been initialized with {@link BTimer_Init}.
+ * If the timer is in running state, it must be associated with this reactor.
+ * The timer enters running state, associated with this reactor.
+ *
+ * @param bsys the object
+ * @param bt timer to start
+ * @param after relative expiration time
+ */
+void BReactor_SetTimerAfter (BReactor *bsys, BTimer *bt, btime_t after);
+
 /**
  * Starts a timer to expire at the specified time.
  * The timer must have been initialized with {@link BTimer_Init}.