aboutsummaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2017-02-15 22:35:52 +0200
committerOskari Timperi <oskari.timperi@iki.fi>2017-02-15 22:35:52 +0200
commit96fad648096614c13e784f11f0e90a583e567de1 (patch)
tree24931f887bc29764a2db1b1ed09b5a7b268d16c8 /src/misc.c
parentd94ae26d161be87c58906dac10519e8156469923 (diff)
downloadmqtt-96fad648096614c13e784f11f0e90a583e567de1.tar.gz
mqtt-96fad648096614c13e784f11f0e90a583e567de1.zip
Make the code compile using MinGW
- implemented GetCurrentTime() for Windows - had to rename GetCurrentTime() to MqttGetCurrentTime() because of name clashes - setup headers correctly
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/misc.c b/src/misc.c
index f276020..d6f9e64 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -4,9 +4,23 @@
#include <time.h>
#if defined(_WIN32)
-#error GetCurrentTime implementation missing
+#include "win32.h"
+int64_t MqttGetCurrentTime()
+{
+ static volatile long once = 0;
+ static LARGE_INTEGER frequency;
+ LARGE_INTEGER counter;
+ if (InterlockedCompareExchange(&once, 1, 0) == 0)
+ {
+ QueryPerformanceFrequency(&frequency);
+ }
+ QueryPerformanceCounter(&counter);
+ counter.QuadPart *= 1000;
+ counter.QuadPart /= frequency.QuadPart;
+ return counter.QuadPart;
+}
#else
-int64_t GetCurrentTime()
+int64_t MqttGetCurrentTime()
{
struct timespec t;