From a8bf23a05c12f2c41e8a469feaed3bac2abb01df Mon Sep 17 00:00:00 2001 From: Stefan Pöschel Date: Wed, 15 Feb 2017 11:43:14 +0100 Subject: Fix sleep delay to include encoding time Up to now the delay between two loop runs was slightly higher than the specified sleep delay as the sleeping process did not consider the time the PAD encoding needs but rather sleeped for the set sleep delay. This is now fixed by using a steady clock. --- src/odr-padenc.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/odr-padenc.cpp b/src/odr-padenc.cpp index d82d4c8..0d19fd6 100644 --- a/src/odr-padenc.cpp +++ b/src/odr-padenc.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -304,6 +305,8 @@ int main(int argc, char *argv[]) { std::list slides_to_transmit; History slides_history(History::MAXHISTORYLEN); + std::chrono::steady_clock::time_point next_run = std::chrono::steady_clock::now(); + while(1) { // try to read slides dir (if present) if (sls_dir && slides_to_transmit.empty()) { @@ -349,7 +352,9 @@ int main(int argc, char *argv[]) { // flush all remaining PADs pad_packetizer.WriteAllPADs(output_fd); - sleep(sleepdelay); + // sleep until next run + next_run += std::chrono::seconds(sleepdelay); + std::this_thread::sleep_until(next_run); } return 1; -- cgit v1.2.3