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 <richardcochran@gmail.com>
master
Richard Cochran 2018-04-24 21:33:24 -07:00
parent b2a36350bb
commit 6f96ebb7b8
4 changed files with 15 additions and 3 deletions

View File

@ -758,6 +758,11 @@ struct config *clock_config(struct clock *c)
return c->config; 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) struct currentDS *clock_current_dataset(struct clock *c)
{ {
return &c->cur; return &c->cur;

View File

@ -79,6 +79,13 @@ struct config *clock_config(struct clock *c);
*/ */
struct currentDS *clock_current_dataset(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. * Obtains the required time stamping mode.
* @param c The clock instance. * @param c The clock instance.

5
port.c
View File

@ -2191,9 +2191,11 @@ void port_close(struct port *p)
struct foreign_clock *port_compute_best(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 foreign_clock *fc;
struct ptp_message *tmp; struct ptp_message *tmp;
dscmp = clock_dscmp(p->clock);
p->best = NULL; p->best = NULL;
LIST_FOREACH(fc, &p->foreign_masters, list) { LIST_FOREACH(fc, &p->foreign_masters, list) {
@ -2210,7 +2212,7 @@ struct foreign_clock *port_compute_best(struct port *p)
if (!p->best) if (!p->best)
p->best = fc; 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; p->best = fc;
else else
fc_clear(fc); 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->state_machine = clock_slave_only(clock) ? ptp_slave_fsm : ptp_fsm;
p->dscmp = dscmp;
p->phc_index = phc_index; p->phc_index = phc_index;
p->jbod = config_get_int(cfg, interface->name, "boundary_clock_jbod"); p->jbod = config_get_int(cfg, interface->name, "boundary_clock_jbod");
transport = config_get_int(cfg, interface->name, "network_transport"); transport = config_get_int(cfg, interface->name, "network_transport");

View File

@ -88,7 +88,6 @@ struct port {
unsigned int multiple_pdr_detected; unsigned int multiple_pdr_detected;
enum port_state (*state_machine)(enum port_state state, enum port_state (*state_machine)(enum port_state state,
enum fsm_event event, int mdiff); enum fsm_event event, int mdiff);
int (*dscmp)(struct dataset *a, struct dataset *b);
/* portDS */ /* portDS */
struct PortIdentity portIdentity; struct PortIdentity portIdentity;
enum port_state state; /*portState*/ enum port_state state; /*portState*/