dovecot-2.2: lib: Created timeval_cmp_margin().
dovecot at dovecot.org
dovecot at dovecot.org
Tue Sep 30 21:14:45 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/e45dda2d7cd6
changeset: 17855:e45dda2d7cd6
user: Stephan Bosch <stephan at rename-it.nl>
date: Wed Oct 01 00:13:36 2014 +0300
description:
lib: Created timeval_cmp_margin().
It's identical to timeval_cmp(), except that it ignores tv_usec differences
smaller than a specified margin.
diffstat:
src/lib/time-util.c | 15 +++++++++++++++
src/lib/time-util.h | 3 +++
2 files changed, 18 insertions(+), 0 deletions(-)
diffs (38 lines):
diff -r bad8e61e2e88 -r e45dda2d7cd6 src/lib/time-util.c
--- a/src/lib/time-util.c Wed Oct 01 00:06:19 2014 +0300
+++ b/src/lib/time-util.c Wed Oct 01 00:13:36 2014 +0300
@@ -20,6 +20,21 @@
return 0;
}
+int timeval_cmp_margin(const struct timeval *tv1, const struct timeval *tv2,
+ unsigned int usec_margin)
+{
+ if (tv1->tv_sec < tv2->tv_sec)
+ return -1;
+ if (tv1->tv_sec > tv2->tv_sec)
+ return 1;
+
+ if (tv1->tv_usec - tv2->tv_usec < (int)usec_margin)
+ return -1;
+ if (tv1->tv_usec - tv2->tv_usec > (int)usec_margin)
+ return -1;
+ return 0;
+}
+
int timeval_diff_msecs(const struct timeval *tv1, const struct timeval *tv2)
{
return timeval_diff_usecs(tv1, tv2) / 1000;
diff -r bad8e61e2e88 -r e45dda2d7cd6 src/lib/time-util.h
--- a/src/lib/time-util.h Wed Oct 01 00:06:19 2014 +0300
+++ b/src/lib/time-util.h Wed Oct 01 00:13:36 2014 +0300
@@ -5,6 +5,9 @@
/* Returns -1 if tv1<tv2, 1 if tv1>tv2, 0 if they're equal. */
int timeval_cmp(const struct timeval *tv1, const struct timeval *tv2);
+/* Same as timeval_cmp, but tv->usecs must differ by at least usec_margin */
+int timeval_cmp_margin(const struct timeval *tv1, const struct timeval *tv2,
+ unsigned int usec_margin);
/* Returns tv1-tv2 in milliseconds. */
int timeval_diff_msecs(const struct timeval *tv1, const struct timeval *tv2);
/* Returns tv1-tv2 in microseconds. */
More information about the dovecot-cvs
mailing list