aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Pöschel <github@basicmaster.de>2017-02-15 11:43:14 +0100
committerStefan Pöschel <github@basicmaster.de>2017-02-15 11:43:14 +0100
commita8bf23a05c12f2c41e8a469feaed3bac2abb01df (patch)
treea9cd027c0291f5dbf4d5ec8555af5d4cb82c7c82
parent3b7b62efc4cdc2997d36dea58b13d43bfe5544da (diff)
downloadODR-PadEnc-a8bf23a05c12f2c41e8a469feaed3bac2abb01df.tar.gz
ODR-PadEnc-a8bf23a05c12f2c41e8a469feaed3bac2abb01df.tar.bz2
ODR-PadEnc-a8bf23a05c12f2c41e8a469feaed3bac2abb01df.zip
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.
-rw-r--r--src/odr-padenc.cpp7
1 files changed, 6 insertions, 1 deletions
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 <stdlib.h>
#include <string>
#include <list>
+#include <thread>
#include <vector>
#include <sys/types.h>
#include <fcntl.h>
@@ -304,6 +305,8 @@ int main(int argc, char *argv[]) {
std::list<slide_metadata_t> 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;