From 83f637fb8e2324948b385569af7f838622b7cf2e Mon Sep 17 00:00:00 2001 From: Jiri Benc Date: Thu, 14 Aug 2014 15:56:04 +0200 Subject: [PATCH] Lazy regeneration of pollfd There's no need to regenerate pollfd multiple times during batches of port operations (like creating of the clock). Just be lazy and regenerate it only once it's needed. Signed-off-by: Jiri Benc --- clock.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/clock.c b/clock.c index 3c6e5ce..55a662f 100644 --- a/clock.c +++ b/clock.c @@ -85,6 +85,7 @@ struct clock { LIST_HEAD(ports_head, port) ports; struct port *uds_port; struct pollfd *pollfd; + int pollfd_valid; int nports; /* does not include the UDS port */ int free_running; int freq_est_interval; @@ -1002,16 +1003,24 @@ static void clock_fill_pollfd(struct pollfd *dest, struct port *p) dest[i].events = POLLIN|POLLPRI; } -void clock_fda_changed(struct clock *c) +static void clock_check_pollfd(struct clock *c) { struct port *p; struct pollfd *dest = c->pollfd; + if (c->pollfd_valid) + return; LIST_FOREACH(p, &c->ports, list) { clock_fill_pollfd(dest, p); dest += N_CLOCK_PFD; } clock_fill_pollfd(dest, c->uds_port); + c->pollfd_valid = 1; +} + +void clock_fda_changed(struct clock *c) +{ + c->pollfd_valid = 0; } static int clock_do_forward_mgmt(struct clock *c, @@ -1212,6 +1221,7 @@ int clock_poll(struct clock *c) struct pollfd *cur; struct port *p; + clock_check_pollfd(c); cnt = poll(c->pollfd, (c->nports + 1) * N_CLOCK_PFD, -1); if (cnt < 0) { if (EINTR == errno) {