Pārlūkot izejas kodu

Add custom implementation of usleep for windows

Filip Klembara 4 gadi atpakaļ
vecāks
revīzija
3f9565b55d
1 mainītis faili ar 18 papildinājumiem un 0 dzēšanām
  1. 18 0
      examples/streamer/stream.cpp

+ 18 - 0
examples/streamer/stream.cpp

@@ -19,6 +19,24 @@
 #include "stream.hpp"
 #include "stream.hpp"
 #include "helpers.hpp"
 #include "helpers.hpp"
 
 
+#if _WIN32
+// taken from https://stackoverflow.com/questions/5801813/c-usleep-is-obsolete-workarounds-for-windows-mingw
+#include <windows.h>
+
+void usleep(__int64 usec)
+{
+    HANDLE timer;
+    LARGE_INTEGER ft;
+
+    ft.QuadPart = -(10*usec); // Convert to 100 nanosecond interval, negative value indicates relative time
+
+    timer = CreateWaitableTimer(NULL, TRUE, NULL);
+    SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
+    WaitForSingleObject(timer, INFINITE);
+    CloseHandle(timer);
+}
+#endif
+
 void StreamSource::stop() {
 void StreamSource::stop() {
     sampleTime_us = 0;
     sampleTime_us = 0;
     sample = {};
     sample = {};