summaryrefslogtreecommitdiff
path: root/src/libstddjb/tain_now_set_stopwatch.c
blob: ef869f73c0fc2641f4132944784ff412b64b138d (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
/* 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_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