tmv: Generalise tmv_eq() to tmv_cmp()

Time values are compared using an inequality test in mmedian.c
Generalise tmv_eq() to tmv_cmp() (by analogy with memcmp()) and
replace existing uses of tmv_eq().

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
master
Michael Brown 2018-03-01 18:12:24 +00:00 committed by Richard Cochran
parent ea82ae6c28
commit 1b7ff890be
4 changed files with 6 additions and 5 deletions

View File

@ -578,7 +578,7 @@ static enum servo_state clock_no_adjust(struct clock *c, tmv_t ingress,
if (f->count < f->max_count) {
return state;
}
if (tmv_eq(ingress, f->ingress1)) {
if (tmv_cmp(ingress, f->ingress1) == 0) {
pr_warning("bad timestamps in rate ratio calculation");
return state;
}

View File

@ -60,7 +60,8 @@ static tmv_t mmedian_sample(struct filter *filter, tmv_t sample)
/* Insert index of the new value to order. */
for (i = m->cnt - 1; i > 0; i--) {
if (m->samples[m->order[i - 1]] <= m->samples[m->index])
if (tmv_cmp(m->samples[m->order[i - 1]],
m->samples[m->index]) <= 0)
break;
m->order[i] = m->order[i - 1];
}

2
port.c
View File

@ -933,7 +933,7 @@ static void port_nrate_calculate(struct port *p, tmv_t origin, tmv_t ingress)
if (n->count < n->max_count) {
return;
}
if (tmv_eq(ingress, n->ingress1)) {
if (tmv_cmp(ingress, n->ingress1) == 0) {
pr_warning("bad timestamps in nrate calculation");
return;
}

4
tmv.h
View File

@ -51,9 +51,9 @@ static inline tmv_t tmv_div(tmv_t a, int divisor)
return a / divisor;
}
static inline int tmv_eq(tmv_t a, tmv_t b)
static inline int tmv_cmp(tmv_t a, tmv_t b)
{
return a == b ? 1 : 0;
return a == b ? 0 : a > b ? +1 : -1;
}
static inline int tmv_is_zero(tmv_t x)