90#define YF_TIME_NTP_USEC_MASK UINT64_C(0xfffffffffffff800)
95#define YF_TIME_INIT { 0 }
100#define YF_DIFFTIME_INIT { 0 }
106#define YF_DIFFTIME_INIT_MILLI(ms_) { INT64_C(1000000) * (ms_) }
111static const yfTime_t yfTimeZeroConstant = YF_TIME_INIT;
116static const yfDiffTime_t yfDiffTimeZeroConstant = YF_DIFFTIME_INIT;
151static inline gboolean
155 return (0 != yftime.t);
170 yftime_new->t = yftime_old.t + yfdifftime.d;
185 yftime_new->t = yftime_old.t - yfdifftime.d;
197#define yfTimeCmpOp(yftime_a, yftime_b, oper_) \
198 ((yftime_a).t oper_ (yftime_b).t)
213 return ((yftime_a.t < yftime_b.t) ? -1 : (yftime_a.t > yftime_b.t));
228 yfdiff->d = yftime_end.t - yftime_start.t;
238 const uint64_t epoch_usec)
240 yftime->t = UINT64_C(1000) * epoch_usec;
250 const uint64_t epoch_msec)
252 yftime->t = UINT64_C(1000000) * epoch_msec;
262 const uint64_t epoch_nsec)
264 yftime->t = epoch_nsec;
281 const uint64_t NTP_EPOCH_TO_UNIX_EPOCH = UINT64_C(0x83AA7E80);
284 const uint64_t NANO_MASK = UINT64_C(0xffffffff);
286 const uint64_t NANO_PER_SEC = UINT64_C(1000000000);
289 const uint64_t MICRO_MASK = UINT64_C(0xfffff800);
291 const uint64_t MICRO_PER_SEC = UINT64_C(1000000);
295 const uint64_t NTP_ROLLOVER = UINT64_C(0x100000000);
300 const uint64_t ROUNDING_DIFF = UINT64_C(0x80000000);
309 yftime->t = ((ntp & NANO_MASK) * NANO_PER_SEC + ROUNDING_DIFF) >> 32;
314 yftime->t = ((((ntp & MICRO_MASK) * MICRO_PER_SEC + ROUNDING_DIFF)
327 yftime->t += ((ntp >> 32) - NTP_EPOCH_TO_UNIX_EPOCH) * NANO_PER_SEC;
331 yftime->t += (((ntp >> 32) + NTP_ROLLOVER - NTP_EPOCH_TO_UNIX_EPOCH)
343 const uint64_t epoch_sec)
345 yftime->t = UINT64_C(1000000000) * epoch_sec;
355 const struct timespec *tspec)
357 yftime->t = UINT64_C(1000000000) * tspec->tv_sec + tspec->tv_nsec;
369 yftime->t = UINT64_C(1000000000) * yfspec32->tv_sec + yfspec32->tv_frac;
379 const struct timeval *tval)
381 yftime->t = (UINT64_C(1000000000) * tval->tv_sec
382 + UINT64_C(1000) * tval->tv_usec);
394 yftime->t = (UINT64_C(1000000000) * yfval32->tv_sec
395 + UINT64_C(1000) * yfval32->tv_frac);
402static inline gboolean
408 return (later_time.t > earlier_time.t + elapsed.d);
420 gettimeofday(&ct, NULL);
421 yfTimeFromTimeval(yftime, &ct);
429static inline uint64_t
433 const uint64_t divisor = UINT64_C(1000);
435 return yftime.t / divisor;
442static inline uint64_t
446 const uint64_t divisor = UINT64_C(1000000);
448 return yftime.t / divisor;
455static inline uint64_t
477 const uint64_t NTP_EPOCH_TO_UNIX_EPOCH = UINT64_C(0x83AA7E80);
479 const long long divisor = 1000000000LL;
481 lldiv_t split = lldiv(yftime.t, divisor);
488 sec = (uint64_t)split.quot + NTP_EPOCH_TO_UNIX_EPOCH;
493 frac = (((uint64_t)split.rem) << UINT64_C(32)) / divisor;
495 *ntp = ((sec << UINT64_C(32)) | frac);
502static inline uint64_t
506 const uint64_t divisor = UINT64_C(1000000000);
508 return yftime.t / divisor;
522 const long long nsec_per_msec = 1000000LL;
523 const long long msec_per_sec = 1000LL;
524 lldiv_t sec = lldiv((yftime.t / nsec_per_msec), msec_per_sec);
526 tmilli->tv_sec = sec.quot;
527 tmilli->tv_msec = sec.rem;
536 struct timespec *tspec,
539 const long long divisor = 1000000000LL;
540 lldiv_t sec = lldiv(yftime.t, divisor);
542 tspec->tv_sec = sec.quot;
543 tspec->tv_nsec = sec.rem;
556 const long long divisor = 1000000000LL;
557 lldiv_t sec = lldiv(yftime.t, divisor);
559 yfspec32->tv_sec = sec.quot;
560 yfspec32->tv_frac = sec.rem;
569 struct timeval *tval,
574 const long long nsec_per_usec = 1000LL;
575 const long long usec_per_sec = 1000000LL;
576 lldiv_t sec = lldiv((yftime.t / nsec_per_usec), usec_per_sec);
578 tval->tv_sec = sec.quot;
579 tval->tv_usec = sec.rem;
594 const long long nsec_per_usec = 1000LL;
595 const long long usec_per_sec = 1000000LL;
596 lldiv_t sec = lldiv((yftime.t / nsec_per_usec), usec_per_sec);
598 yfval32->tv_sec = sec.quot;
599 yfval32->tv_frac = sec.rem;
625static inline gboolean
629 return (0 != yfdifftime.d);
646 yfdiff_new->d = yfdiff_old.d + yfdiff_addend.d;
665 yfdiff_new->d = yfdiff_old.d - yfdiff_subtrahend.d;
675#define yfDiffTimeCmpOp(yfdiff_a, yfdiff_b, oper_) \
676 ((yfdiff_a).d oper_ (yfdiff_b).d)
685 const int64_t diff_usec)
687 yfdifftime->d = INT64_C(1000) * diff_usec;
697 const int64_t diff_msec)
699 yfdifftime->d = INT64_C(1000000) * diff_msec;
707yfDiffTimeFromSeconds(
709 const int64_t diff_sec)
711 yfdifftime->d = INT64_C(1000000000) * diff_sec;
721 const double divisor = 1e9;
723 return (
double)yfdifftime.d / divisor;
734 const int64_t divisor = INT64_C(1000000);
736 return yfdifftime.d / divisor;
747 const int64_t divisor = INT64_C(1000);
749 return yfdifftime.d / divisor;
768yfDiffTimeToTimemilli(
774 const long long nsec_per_msec = 1000000LL;
775 const long long msec_per_sec = 1000LL;
778 sec = lldiv((yfdifftime.d / nsec_per_msec), msec_per_sec);
780 tmilli->tv_sec = sec.quot;
781 tmilli->tv_msec = sec.rem;
791 struct timespec *tspec,
794 const long long divisor = 1000000000LL;
795 lldiv_t sec = lldiv(yfdifftime.d, divisor);
797 tspec->tv_sec = sec.quot;
798 tspec->tv_nsec = sec.rem;
807 struct timeval *tval,
812 const long long nsec_per_usec = 1000LL;
813 const long long usec_per_sec = 1000000LL;
816 sec = lldiv((yfdifftime.d / nsec_per_usec), usec_per_sec);
818 tval->tv_sec = sec.quot;
819 tval->tv_usec = sec.rem;
A structure similar to timeval and timespec but which stores seconds and milliseconds.
Definition yaftime.h:75
Some high-performance network cards use a custom 64-bit structure similar to the standard timeval or ...
Definition yaftime.h:66
YAF time difference: represents the difference of two yfTime_t.
Definition yaftime.h:55
YAF timestamp: represents a moment in time.
Definition yaftime.h:47