# Use epoll (needs support in libc and kernel, default: auto-detect)
# Set("CONFIG_UCW_EPOLL");
+# Use monotonic clock (default: yes on Linux, no elsewhere)
+# Set("CONFIG_UCW_MONOTONIC_CLOCK");
+
# Which regular expression library should be used? If none is selected, we use BSD regex from libc.
UnSet("CONFIG_UCW_POSIX_REGEX");
UnSet("CONFIG_UCW_PCRE");
regex=
#endif
+#ifdef CONFIG_UCW_MONOTONIC_CLOCK
+rt=-lrt
+#else
+rt=
+#endif
+
# Override if you want to use the -pic version
picsuffix=
Description: A library of utility functions and data structures
Version: @UCW_VERSION@
Cflags: -I${incdir}
-Libs: -L${libdir} -lucw${picsuffix} ${threads} ${regex}
+Libs: -L${libdir} -lucw${picsuffix} ${threads} ${regex} ${rt}
FINIS
});
+# Check if we want to use monotonic clock
+TestBool("CONFIG_UCW_MONOTONIC_CLOCK", "Checking for monotonic clock", sub {
+ return Get("CONFIG_LINUX");
+});
+
# Darwin does not support BSD regexes, fix up
if (IsSet("CONFIG_DARWIN")) {
if (!IsSet("CONFIG_UCW_POSIX_REGEX") && !IsSet("CONFIG_UCW_PCRE")) {
/*
* UCW Library -- A Simple Millisecond Timer
*
- * (c) 2007 Martin Mares <mj@ucw.cz>
+ * (c) 2007--2012 Martin Mares <mj@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
+#include <time.h>
+
+#ifdef CONFIG_UCW_MONOTONIC_CLOCK
+
+timestamp_t
+get_timestamp(void)
+{
+ struct timespec ts;
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
+ die("clock_gettime failed: %m");
+ return (timestamp_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
+}
+
+#else
timestamp_t
get_timestamp(void)
;
}
+#endif
+
void
init_timer(timestamp_t *timer)
{
*newt = get_timestamp();
return MIN(*newt-*oldt, ~0U);
}
+
+#ifdef TEST
+
+#include <stdio.h>
+
+int main(void)
+{
+ printf("%ju\n", (intmax_t) get_timestamp());
+ return 0;
+}
+
+#endif