diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-03-05 17:28:24 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-03-05 17:28:24 +0100 |
commit | 126cc8829c003d483839fd230f979e47dcf856ae (patch) | |
tree | acddeb0426ea10cc147cad633fc11633e6bc4a50 /src/dabOutput/dabOutputSimul.cpp | |
parent | 57eb1f4cb909c233131b48ae481a3e4826e309ff (diff) | |
download | dabmux-126cc8829c003d483839fd230f979e47dcf856ae.tar.gz dabmux-126cc8829c003d483839fd230f979e47dcf856ae.tar.bz2 dabmux-126cc8829c003d483839fd230f979e47dcf856ae.zip |
Replace platform specific simul:// by C++11 chrono
Diffstat (limited to 'src/dabOutput/dabOutputSimul.cpp')
-rw-r--r-- | src/dabOutput/dabOutputSimul.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
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; |