From 6f96ebb7b81b8595fc4233bceb786124a717e9f4 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Tue, 24 Apr 2018 21:33:24 -0700 Subject: [PATCH] Refactor the data set comparison function variable. There is no need to keep two copies of the data set comparison function. This patch adds a method that allows the port code to obtain the function from the clock code. Signed-off-by: Richard Cochran --- clock.c | 5 +++++ clock.h | 7 +++++++ port.c | 5 +++-- port_private.h | 1 - 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/clock.c b/clock.c index afee960..2cefd9f 100644 --- a/clock.c +++ b/clock.c @@ -758,6 +758,11 @@ struct config *clock_config(struct clock *c) return c->config; } +int (*clock_dscmp(struct clock *c))(struct dataset *a, struct dataset *b) +{ + return c->dscmp; +} + struct currentDS *clock_current_dataset(struct clock *c) { return &c->cur; diff --git a/clock.h b/clock.h index 3fa026d..d6a79bd 100644 --- a/clock.h +++ b/clock.h @@ -79,6 +79,13 @@ struct config *clock_config(struct clock *c); */ struct currentDS *clock_current_dataset(struct clock *c); +/** + * Obtains the clock's data set comparison function. + * @param c The clock instance. + * @return A pointer to the data set comparison function, without fail. + */ +int (*clock_dscmp(struct clock *c))(struct dataset *a, struct dataset *b); + /** * Obtains the required time stamping mode. * @param c The clock instance. diff --git a/port.c b/port.c index 1757dfe..9afc06b 100644 --- a/port.c +++ b/port.c @@ -2191,9 +2191,11 @@ void port_close(struct port *p) struct foreign_clock *port_compute_best(struct port *p) { + int (*dscmp)(struct dataset *a, struct dataset *b); struct foreign_clock *fc; struct ptp_message *tmp; + dscmp = clock_dscmp(p->clock); p->best = NULL; LIST_FOREACH(fc, &p->foreign_masters, list) { @@ -2210,7 +2212,7 @@ struct foreign_clock *port_compute_best(struct port *p) if (!p->best) p->best = fc; - else if (p->dscmp(&fc->dataset, &p->best->dataset) > 0) + else if (dscmp(&fc->dataset, &p->best->dataset) > 0) p->best = fc; else fc_clear(fc); @@ -2784,7 +2786,6 @@ struct port *port_open(int phc_index, } p->state_machine = clock_slave_only(clock) ? ptp_slave_fsm : ptp_fsm; - p->dscmp = dscmp; p->phc_index = phc_index; p->jbod = config_get_int(cfg, interface->name, "boundary_clock_jbod"); transport = config_get_int(cfg, interface->name, "network_transport"); diff --git a/port_private.h b/port_private.h index 860a2bb..f8771c7 100644 --- a/port_private.h +++ b/port_private.h @@ -88,7 +88,6 @@ struct port { unsigned int multiple_pdr_detected; enum port_state (*state_machine)(enum port_state state, enum fsm_event event, int mdiff); - int (*dscmp)(struct dataset *a, struct dataset *b); /* portDS */ struct PortIdentity portIdentity; enum port_state state; /*portState*/