]> sigrok.org Git - libserialport.git/commitdiff
Use clock_gettime(CLOCK_MONOTONIC) if available.
authorMartin Ling <redacted>
Sun, 23 Sep 2018 16:28:11 +0000 (17:28 +0100)
committerMartin Ling <redacted>
Sat, 28 Dec 2019 21:02:19 +0000 (22:02 +0100)
Should fix #759 except on OSX versions below 10.12, which don't
have clock_gettime.

libserialport_internal.h
serialport.c

index 3f01b6dae5f6ccf5456e77610793236d4182d517..ec15f58fecd359625e11727ce32507009bd2e559 100644 (file)
@@ -53,6 +53,7 @@
 #include <termios.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
+#include <time.h>
 #include <poll.h>
 #endif
 #ifdef __APPLE__
index 07a0aaa54b915fac58053e83c7541c55de925c89..15ca1fda35bc9e85f4404c18109c4cd7c9c10beb 100644 (file)
@@ -59,7 +59,14 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data,
 
 static void get_time(struct timeval *time)
 {
+#ifdef HAVE_CLOCK_GETTIME
+       struct timespec ts;
+       clock_gettime(CLOCK_MONOTONIC, &ts);
+       time->tv_sec = ts.tv_sec;
+       time->tv_usec = ts.tv_nsec / 1000;
+#else
        gettimeofday(time, NULL);
+#endif
 }
 
 SP_API enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_ptr)