summaryrefslogtreecommitdiff
path: root/src/libstddjb/tain_now_set_stopwatch.c
blob: fd31950f757c40dc52716497e838317f624132ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* ISC license. */

/* MT-unsafe */

#include <skalibs/sysdeps.h>
#include <skalibs/tai.h>

#if defined(SKALIBS_HASCLOCKRT) && (defined(SKALIBS_HASCLOCKMON) || defined(SKALIBS_HASCLOCKBOOT))

#include <time.h>

#ifdef SKALIBS_HASCLOCKMON
# define SKALIBS_STOPWATCH CLOCK_MONOTONIC
#else
# define SKALIBS_STOPWATCH CLOCK_BOOTTIME
#endif

static tain offset ;

static int tain_now_stopwatch (tain *now)
{
  return tain_stopwatch_read(now, SKALIBS_STOPWATCH, &offset) ;
}

int tain_now_set_stopwatch (tain *now)
{
  if (!tain_stopwatch_init(now, SKALIBS_STOPWATCH, &offset))
    return tain_now_set_wallclock(now) ;
  tain_now = &tain_now_stopwatch ;
  return 1 ;
}

#else

int tain_now_set_stopwatch (tain *now)
{
  return tain_now_set_wallclock(now) ;
}

#endif