Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to compile on OSX #7

Open
DanielO opened this issue Jul 6, 2018 · 5 comments
Open

Patch to compile on OSX #7

DanielO opened this issue Jul 6, 2018 · 5 comments

Comments

@DanielO
Copy link

DanielO commented Jul 6, 2018

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

@russdill
Copy link
Owner

CLOCK_MONOTONIC doesn't advance during suspend. I think mach_continuous_time is the macos equivalent.

@DanielO
Copy link
Author

DanielO commented Sep 19, 2018

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.

@russdill
Copy link
Owner

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

@DanielO
Copy link
Author

DanielO commented Sep 19, 2018

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)

@russdill
Copy link
Owner

Thanks, will merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants