summaryrefslogtreecommitdiff
path: root/src/libstddjb
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb')
-rw-r--r--src/libstddjb/sysclock_get.c10
-rw-r--r--src/libstddjb/sysclock_set.c14
-rw-r--r--src/libstddjb/tain_clockmon.c47
-rw-r--r--src/libstddjb/tain_now.c44
-rw-r--r--src/libstddjb/tain_now_set_stopwatch.c36
-rw-r--r--src/libstddjb/tain_now_set_wallclock.c10
-rw-r--r--src/libstddjb/tain_stopwatch.c50
-rw-r--r--src/libstddjb/tain_wallclock_read.c (renamed from src/libstddjb/tain_sysclock.c)2
-rw-r--r--src/libstddjb/timestamp_r.c2
9 files changed, 103 insertions, 112 deletions
diff --git a/src/libstddjb/sysclock_get.c b/src/libstddjb/sysclock_get.c
index 3d14f96..6c5041d 100644
--- a/src/libstddjb/sysclock_get.c
+++ b/src/libstddjb/sysclock_get.c
@@ -1,17 +1,9 @@
/* ISC license. */
-#include <skalibs/config.h>
#include <skalibs/sysdeps.h>
#include <skalibs/tai.h>
-#ifdef SKALIBS_FLAG_USERT
-# ifndef SKALIBS_HASCLOCKRT
-# undef SKALIBS_FLAG_USERT
-# warning "SKALIBS_FLAG_USERT set but SKALIBS_HASCLOCKRT not found. Clearing SKALIBS_FLAG_USERT."
-# endif
-#endif
-
-#ifdef SKALIBS_FLAG_USERT
+#ifdef SKALIBS_HASCLOCKRT
#include <time.h>
diff --git a/src/libstddjb/sysclock_set.c b/src/libstddjb/sysclock_set.c
index 0ec51c6..57e2abe 100644
--- a/src/libstddjb/sysclock_set.c
+++ b/src/libstddjb/sysclock_set.c
@@ -2,24 +2,16 @@
/* MT-unsafe */
-#include <skalibs/config.h>
#include <skalibs/sysdeps.h>
-#ifdef SKALIBS_FLAG_USERT
-# ifndef SKALIBS_HASCLOCKRT
-# undef SKALIBS_FLAG_USERT
-# warning "SKALIBS_FLAG_USERT set but SKALIBS_HASCLOCKRT not found. Clearing SKALIBS_FLAG_USERT."
-# endif
-#endif
-
-#ifndef SKALIBS_FLAG_USERT
+#ifndef SKALIBS_HASCLOCKRT
# ifndef SKALIBS_HASSETTIMEOFDAY
-# error "SKALIBS_FLAG_USERT clear but SKALIBS_HASSETTIMEOFDAY not found. How do your set your system clock?"
+# error "neither clockrt nor settimeofday sysdeps are present. How do your set your system clock?"
# endif
#endif
-#ifdef SKALIBS_FLAG_USERT
+#ifdef SKALIBS_HASCLOCKRT
#include <time.h>
#include <skalibs/tai.h>
diff --git a/src/libstddjb/tain_clockmon.c b/src/libstddjb/tain_clockmon.c
deleted file mode 100644
index f14cd31..0000000
--- a/src/libstddjb/tain_clockmon.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* ISC license. */
-
-#include <skalibs/sysdeps.h>
-#include <skalibs/tai.h>
-
-#ifdef SKALIBS_HASCLOCKMON
-
-#include <time.h>
-
-int tain_clockmon_init (tain_t *offset)
-{
- tain_t a, b ;
- struct timespec ts ;
- if (!tain_sysclock(&a)) return 0 ;
- if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) return 0 ;
- if (!tain_from_timespec(&b, &ts)) return 0 ;
- tain_add(&a, &a, &tain_nano500) ;
- tain_sub(offset, &a, &b) ;
- return 1 ;
-}
-
-int tain_clockmon (tain_t *a, tain_t const *offset)
-{
- struct timespec ts ;
- if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) return 0 ;
- if (!tain_from_timespec(a, &ts)) return 0 ;
- tain_add(a, a, offset) ;
- return 1 ;
-}
-
-#else
-
-#include <errno.h>
-
-int tain_clockmon_init (tain_t *offset)
-{
- (void)offset ;
- return (errno = ENOSYS, 0) ;
-}
-
-int tain_clockmon (tain_t *a, tain_t const *offset)
-{
- (void)a ; (void)offset ;
- return (errno = ENOSYS, 0) ;
-}
-
-#endif
diff --git a/src/libstddjb/tain_now.c b/src/libstddjb/tain_now.c
index 157087a..d6625d6 100644
--- a/src/libstddjb/tain_now.c
+++ b/src/libstddjb/tain_now.c
@@ -2,48 +2,6 @@
/* MT-unsafe */
-#include <skalibs/config.h>
-#include <skalibs/sysdeps.h>
#include <skalibs/tai.h>
-#ifdef SKALIBS_FLAG_USEMON
-# ifndef SKALIBS_HASCLOCKMON
-# undef SKALIBS_FLAG_USEMON
-# warning "SKALIBS_FLAG_USEMON set but SKALIBS_HASCLOCKMON not found. Clearing SKALIBS_FLAG_USEMON."
-# endif
-#endif
-
-
-#ifdef SKALIBS_FLAG_USEMON
-
-static tain_t offset ;
-
-int tain_init ()
-{
- return tain_clockmon_init(&offset) ;
-}
-
-int tain_now (tain_t *a)
-{
- static int initted = 0 ;
- if (!initted)
- {
- if (!tain_clockmon_init(&offset)) return 0 ;
- initted = 1 ;
- }
- return tain_clockmon(a, &offset) ;
-}
-
-#else
-
-int tain_init ()
-{
- return 1 ;
-}
-
-int tain_now (tain_t *a)
-{
- return tain_sysclock(a) ;
-}
-
-#endif
+tain_clockread_func_t_ref tain_now = &tain_wallclock_read ;
diff --git a/src/libstddjb/tain_now_set_stopwatch.c b/src/libstddjb/tain_now_set_stopwatch.c
new file mode 100644
index 0000000..184a40a
--- /dev/null
+++ b/src/libstddjb/tain_now_set_stopwatch.c
@@ -0,0 +1,36 @@
+/* ISC license. */
+
+/* MT-unsafe */
+
+#include <skalibs/tai.h>
+
+#if defined(SKALIBS_HAS_CLOCKRT) && (defined(SKALIBS_HAS_CLOCKMON) || defined(SKALIBS_HAS_CLOCKBOOT))
+
+#include <time.h>
+
+#ifdef SKALIBS_HAS_CLOCKMON
+# define SKALIBS_STOPWATCH CLOCK_MONOTONIC
+#else
+# define SKALIBS_STOPWATCH CLOCK_BOOTTIME
+#endif
+
+static tain_t offset ;
+
+static int tain_now_stopwatch (tain_t *a)
+{
+ return tain_stopwatch_read(a, SKALIBS_STOPWATCH, &offset) ;
+}
+
+void tain_now_set_stopwatch (void)
+{
+ if (!tain_stopwatch_init(SKALIBS_STOPWATCH, &offset)) return ;
+ tain_now = &tain_now_stopwatch ;
+}
+
+#else
+
+void tain_now_set_stopwatch (void)
+{
+}
+
+#endif
diff --git a/src/libstddjb/tain_now_set_wallclock.c b/src/libstddjb/tain_now_set_wallclock.c
new file mode 100644
index 0000000..a3d8b61
--- /dev/null
+++ b/src/libstddjb/tain_now_set_wallclock.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+/* MT-unsafe */
+
+#include <skalibs/tai.h>
+
+void tain_now_set_wallclock (void)
+{
+ tain_now = &tain_wallclock_read ;
+}
diff --git a/src/libstddjb/tain_stopwatch.c b/src/libstddjb/tain_stopwatch.c
new file mode 100644
index 0000000..2bb4974
--- /dev/null
+++ b/src/libstddjb/tain_stopwatch.c
@@ -0,0 +1,50 @@
+/* ISC license. */
+
+#include <skalibs/sysdeps.h>
+#include <skalibs/tai.h>
+
+#if defined(SKALIBS_HASCLOCKRT) && (defined(SKALIBS_HASCLOCKMON) || defined(SKALIBS_HASCLOCKBOOT))
+
+#include <time.h>
+
+int tain_stopwatch_init (clock_t cl, tain_t *offset)
+{
+ tain_t a, b ;
+ struct timespec ts ;
+ if (!tain_wallclock_read(&a)) return 0 ;
+ if (clock_gettime(cl, &ts) < 0) return 0 ;
+ if (!tain_from_timespec(&b, &ts)) return 0 ;
+ tain_add(&a, &a, &tain_nano500) ;
+ tain_sub(offset, &a, &b) ;
+ return 1 ;
+}
+
+int tain_stopwatch_read (tain_t *a, clock_t cl, tain_t const *offset)
+{
+ struct timespec ts ;
+ if (clock_gettime(cl, &ts) < 0) return 0 ;
+ if (!tain_from_timespec(a, &ts)) return 0 ;
+ tain_add(a, a, offset) ;
+ return 1 ;
+}
+
+#else
+
+#include <errno.h>
+
+int tain_stopwatch_init (clock_t cl, tain_t *offset)
+{
+ (void)cl ;
+ (void)offset ;
+ return (errno = ENOSYS, 0) ;
+}
+
+int tain_stopwatch_read (tain_t *a, clock_t cl, tain_t const *offset)
+{
+ (void)a ;
+ (void)cl ;
+ (void)offset ;
+ return (errno = ENOSYS, 0) ;
+}
+
+#endif
diff --git a/src/libstddjb/tain_sysclock.c b/src/libstddjb/tain_wallclock_read.c
index 3b98eb1..96ed861 100644
--- a/src/libstddjb/tain_sysclock.c
+++ b/src/libstddjb/tain_wallclock_read.c
@@ -2,7 +2,7 @@
#include <skalibs/tai.h>
-int tain_sysclock (tain_t *a)
+int tain_wallclock_read (tain_t *a)
{
tain_t aa ;
if (!sysclock_get(&aa)) return 0 ;
diff --git a/src/libstddjb/timestamp_r.c b/src/libstddjb/timestamp_r.c
index 6eb8ab7..46be7a4 100644
--- a/src/libstddjb/timestamp_r.c
+++ b/src/libstddjb/timestamp_r.c
@@ -4,7 +4,7 @@
int timestamp_r (char *s, tain_t *stamp)
{
- if (!tain_sysclock(stamp)) return 0 ;
+ if (!tain_wallclock_read(stamp)) return 0 ;
timestamp_fmt(s, stamp) ;
return 1 ;
}