summaryrefslogtreecommitdiffstats
path: root/src/dabOutput
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-03-05 17:28:24 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-03-05 17:28:24 +0100
commit126cc8829c003d483839fd230f979e47dcf856ae (patch)
treeacddeb0426ea10cc147cad633fc11633e6bc4a50 /src/dabOutput
parent57eb1f4cb909c233131b48ae481a3e4826e309ff (diff)
downloaddabmux-126cc8829c003d483839fd230f979e47dcf856ae.tar.gz
dabmux-126cc8829c003d483839fd230f979e47dcf856ae.tar.bz2
dabmux-126cc8829c003d483839fd230f979e47dcf856ae.zip
Replace platform specific simul:// by C++11 chrono
Diffstat (limited to 'src/dabOutput')
-rw-r--r--src/dabOutput/dabOutput.h4
-rw-r--r--src/dabOutput/dabOutputSimul.cpp27
2 files changed, 15 insertions, 16 deletions
diff --git a/src/dabOutput/dabOutput.h b/src/dabOutput/dabOutput.h
index 2c4d1ef..6756027 100644
--- a/src/dabOutput/dabOutput.h
+++ b/src/dabOutput/dabOutput.h
@@ -36,7 +36,9 @@
#include <stdexcept>
#include <signal.h>
#include <vector>
+#include <chrono>
#include <memory>
+
#ifdef _WIN32
# include <io.h>
# ifdef __MINGW32__
@@ -305,7 +307,7 @@ class DabOutputSimul : public DabOutput
#ifdef _WIN32
DWORD startTime_;
#else
- struct timespec startTime_;
+ std::chrono::steady_clock::time_point startTime_;
#endif
};
diff --git a/src/dabOutput/dabOutputSimul.cpp b/src/dabOutput/dabOutputSimul.cpp
index 2317750..04ce536 100644
--- a/src/dabOutput/dabOutputSimul.cpp
+++ b/src/dabOutput/dabOutputSimul.cpp
@@ -28,6 +28,8 @@
#include <cstdio>
#include <fcntl.h>
#include <limits.h>
+#include <chrono>
+#include <thread>
#ifdef _WIN32
# include <io.h>
# ifdef __MINGW32__
@@ -49,7 +51,7 @@ int DabOutputSimul::Open(const char* name)
#ifdef _WIN32
startTime_ = GetTickCount();
#else
- clock_gettime(CLOCK_MONOTONIC, &startTime_);
+ startTime_ = std::chrono::steady_clock::now();
#endif
return 0;
@@ -57,11 +59,10 @@ int DabOutputSimul::Open(const char* name)
int DabOutputSimul::Write(void* buffer, int size)
{
+#ifdef _WIN32
unsigned long current;
unsigned long start;
unsigned long waiting;
-
-#ifdef _WIN32
current = GetTickCount();
start = this->startTime_;
if (current < start) {
@@ -75,20 +76,16 @@ int DabOutputSimul::Write(void* buffer, int size)
}
this->startTime_ += 24;
#else
- struct timespec curTime;
- clock_gettime(CLOCK_MONOTONIC, &curTime);
- current = (1000000000ul * curTime.tv_sec) + curTime.tv_nsec;
- start = (1000000000ul * this->startTime_.tv_sec) + this->startTime_.tv_nsec;
- waiting = 24000000ul - (current - start);
- if ((current - start) < 24000000ul) {
- usleep(waiting / 1000);
- }
+ auto curTime = std::chrono::steady_clock::now();
+
+ auto diff = curTime - startTime_;
+ auto waiting = std::chrono::milliseconds(24) - diff;
- this->startTime_.tv_nsec += 24000000;
- if (this->startTime_.tv_nsec >= 1000000000) {
- this->startTime_.tv_nsec -= 1000000000;
- ++this->startTime_.tv_sec;
+ if (diff < std::chrono::milliseconds(24)) {
+ std::this_thread::sleep_for(waiting);
}
+
+ startTime_ += std::chrono::milliseconds(24);
#endif
return size;