Browse Source

Launch epochs no more often than every epoch_interval_us microseconds

Ian Goldberg 1 year ago
parent
commit
565d5a2ba5
1 changed files with 7 additions and 0 deletions
  1. 7 0
      App/start.cpp

+ 7 - 0
App/start.cpp

@@ -154,6 +154,9 @@ static void route_test(NetIO &netio, char **args)
         }
     }
 
+    // The epoch interval, in microseconds
+    uint32_t epoch_interval_us = 1000000;
+
     // Run 10 epochs
     for (int i=0; i<10; ++i) {
         struct timespec tp;
@@ -164,6 +167,10 @@ static void route_test(NetIO &netio, char **args)
         unsigned long end = tp.tv_sec * 1000000 + tp.tv_nsec/1000;
         unsigned long diff = end - start;
         printf("Epoch time: %lu.%06lu s\n", diff/1000000, diff%1000000);
+        // Sleep for the rest of the epoch interval
+        if (diff < epoch_interval_us) {
+            usleep(epoch_interval_us - (useconds_t)diff);
+        }
     }
     netio.close();
 }