skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

tain_stopwatch.c (1045B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/sysdeps.h>
      4 #include <skalibs/tai.h>
      5 
      6 #if defined(SKALIBS_HASCLOCKRT) && (defined(SKALIBS_HASCLOCKMON) || defined(SKALIBS_HASCLOCKBOOT))
      7 
      8 #include <time.h>
      9 
     10 int tain_stopwatch_init (tain *now, clock_t cl, tain *offset)
     11 {
     12   tain a, b ;
     13   struct timespec ts ;
     14   if (clock_gettime(cl, &ts) < 0) return 0 ;
     15   if (!tain_from_timespec(&b, &ts)) return 0 ;
     16   if (!tain_wallclock_read(&a)) return 0 ;
     17   tain_sub(offset, &a, &b) ;
     18   *now = a ;
     19   return 1 ;
     20 }
     21 
     22 int tain_stopwatch_read (tain *now, clock_t cl, tain const *offset)
     23 {
     24   struct timespec ts ;
     25   if (clock_gettime(cl, &ts) < 0) return 0 ;
     26   if (!tain_from_timespec(now, &ts)) return 0 ;
     27   tain_add(now, now, offset) ;
     28   return 1 ;
     29 }
     30 
     31 #else
     32 
     33 #include <errno.h>
     34 
     35 int tain_stopwatch_init (tain *now, clock_t cl, tain *offset)
     36 {
     37   (void)now ;
     38   (void)cl ;
     39   (void)offset ;
     40   return (errno = ENOSYS, 0) ;
     41 }
     42 
     43 int tain_stopwatch_read (tain *now, clock_t cl, tain const *offset)
     44 {
     45   (void)now ;
     46   (void)cl ;
     47   (void)offset ;
     48   return (errno = ENOSYS, 0) ;
     49 }
     50 
     51 #endif