Patch to compile on OSX
These are in addition to the one from issue #5 .
diff --git a/include/arch/cc.h b/include/arch/cc.h
index 9866cc3..ece3d52 100644
--- a/include/arch/cc.h
+++ b/include/arch/cc.h
@@ -6,7 +6,7 @@
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
-#include <endian.h>
+//#include <endian.h>
typedef uint8_t u8_t;
typedef int8_t s8_t;
diff --git a/src/libevent.c b/src/libevent.c
index 746887b..0e4424a 100644
--- a/src/libevent.c
+++ b/src/libevent.c
@@ -74,8 +74,8 @@ u32_t
sys_now(void)
{
struct timespec tp;
- /* CLOCK_BOOTTIME includes time spent in suspend */
- clock_gettime(CLOCK_BOOTTIME, &tp);
+ /* CLOCK_MONOTONIC includes time spent in suspend */
+ clock_gettime(CLOCK_MONOTONIC, &tp);
return tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
}
I don't know if Linux supports CLOCK_MONOTONIC with the same semantics as OSX - if it does that would be best to use IMO.
The #include can probably be dealt with via an #ifdef
CLOCK_MONOTONIC doesn't advance during suspend. I think mach_continuous_time is the macos equivalent.
The man page says it does advance during sleep
CLOCK_MONOTONIC clock that increments monotonically, tracking the time since an arbi-
trary point, and will continue to increment while the system is
asleep.
The man page doesn't mention suspend at all.
https://linux.die.net/man/2/clock_gettime
CLOCK_BOOTTIME (since Linux 2.6.39; Linux-specific) Identical to CLOCK_MONOTONIC, except it also includes any time that the system is suspended. This allows applications to get a suspend-aware monotonic clock without having to deal with the complications of CLOCK_REALTIME, which may have discontinuities if the time is changed using settimeofday(2).
In Linux, this was true until 4.17
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d6ed449afdb38f89a7b38ec50e367559e1b8f71f
Ugh I see, what a pain. How about this then?
@@ -74,8 +74,13 @@ u32_t
sys_now(void)
{
struct timespec tp;
+#ifdef linux
/* CLOCK_BOOTTIME includes time spent in suspend */
clock_gettime(CLOCK_BOOTTIME, &tp);
+#else
+ /* CLOCK_MONOTONIC includes time spent in suspend */
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+#endif
return tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
}
(FreeBSD is the same as OSX)
Thanks, will merge.